On 1 January 2013 09:39, S Krish <[email protected]> wrote:
> testPharoBuffer
> "self new testPharoBuffer "
>     | buf addr  addr2 |
>         buf := String new: 100000.
>         addr := buf asNBExternalString.
>         addr2 := ( NativeBoost allocate: 256 ).
>         self testPharoBuffer: addr . " or use addr2, both of it does not
> work"
>         Transcript cr; show: buf.
>
>
> have tried "addr readString"  / on addr2 .. too
>
> Need to understand how to pass a memory location to the dll function stack
> and get back what is written to the memory in Pharo in a more general sense.
>
>
Hmm.. Did you changed the signature?

    self nbCall:  #( int readAndWritePipe( void * buf  ) ) module:
'TestPharo.dll'

So, if this a String (a variable-byte object) , a function will
receive a pointer to its first byte,
and if its address (NBExternalAddress) then a pointer passed to
function will be equal to that address.

>
> On Tue, Jan 1, 2013 at 12:13 PM, S Krish <[email protected]>
> wrote:
>>
>> I am trying to work with memory addresses back n forth..
>>
>> Simple case of char* buffer that needs to be filled in by dll . Buffer
>> does not change in Pharo after the call. Am I missing something here..
>>
>> The memory address that is printed out does not match what I see in Pharo
>> / infact the address does not change at all... for repeated call invoked
>> from debugger.
>>
>> C Code:
>>
>> DLLEXPORT int readAndWritePipe(char* outBuf )
>> {
>>           system("Echo readAndWritePipe" );
>>           debugPrintf ( "readAndWritePipe: %d \n" , &outBuf , 1046 );
>>           memcpy ( outBuf , "Testing123\0" , 11) ;
>>           return 0;
>> }
>>
>> void debugPrintf ( char* logString, int intArg , char* strArg, int size )
>> { // can redirect as needed to logger end point..
>>              FILE * logFile = fopen( "c:\\temp\\writePipes.log" , "a" );
>>              char* buf = (char*) calloc( sizeof(char) , size );
>>              sprintf( buf, logString , intArg , strArg );
>>              fputs(buf , logFile );
>>              fclose(logFile);
>> }
>>
>> Pharo:
>>
>> testPharoBuffer: buf
>>
>>     <primitive: #primitiveNativeCall module: #NativeBoostPlugin error:
>> errorCode >
>>      ^ self nbCall:  #( int readAndWritePipe( String buf  ) ) module:
>> 'TestPharo.dll'
>>
>>
>> testPharoBuffer
>> "self new testPharoBuffer "
>>     | buf addr  addr2 |
>>         buf := String new: 100000.
>>         addr := buf asNBExternalString.
>>         addr2 := ( NativeBoost allocate: 256 ).
>>         self testPharoBuffer: addr . " or use addr2, both of it does not
>> work"
>>         Transcript cr; show: buf.
>>
>
>



-- 
Best regards,
Igor Stasenko.

Reply via email to