Hello, I have wrapped a dll called shmdll.dll that encapsulates some Shared Memory routines and am trying to access it with Win32::API. I know about the Win32MemMap module but it seems to have a small memory leak in even the simplest cases. Anyway, I have two C routines:

int __export __stdcall SetSharedMem(const int shareIndex, const void* +lpszBuf, const DWORD bufLength) int __export __stdcall GetSharedMem(const int shareIndex,void* lpszBuf +, const DWORD bufLength)
SetSharedMem writes what is passed in the variable lpszBuf (up to character bufLength) into a shared memory location referenced by shareIndex
GetSharedMem gets bufLength characters from that same shared memory location and puts it into lpszBuf

I have two corresponding Win32::API declarations:

$SetSharedMem = Win32::API->new('shmdll', 'int SetSharedMem(int shareI +ndex, VOID* lpszBuf, DWORD bufLength)'); $GetSharedMem = Win32::API->new('shmdll', 'int GetSharedMem(int shareI +ndex,VOID* lpszBuf, DWORD bufLength)');
I don't seem to be having a problem setting the shared memory location but when I get the shared memory location using:

$returnBuff = " " x ($str_length);<br> $return = $GetSharedMem->Call(0,$returnBuff,$str_length);<br><br>
it seems to stop before first null character. I dumped (using Devel::Peek Dump command) the buffer when the shared memory is being set and what was returned. That looks like the following:

Setting:
SV = PV(0x1abed40) at 0x1dea898<br> REFCNT = 1<br> FLAGS = (POK,pPOK)<br> PV = 0x1dda434 "\4\4\0041234\4\4\4\10\3\2\0\0\0\n\r20\0asdfasdfaf\3\0 +\0\0Red\4 \2\1\0\0\0\n\01710|\0|Asdfasdfaf\4\0\0\0Blue"\0<br> CUR = 69<br> LEN = 70<br><br>
Getting:
SV = PV(0x1abed64) at 0x1dea94c<br> REFCNT = 1<br> FLAGS = (POK,pPOK)<br> PV = 0x1dda218 "\4\4\0041234\4\4\4\10\3\2"\0<br> CUR = 13<br> LEN = 71<br><br>
As you can see by the PV value it cuts off before the three nulls in a row. I am using a memcpy in the GetSharedMemory routine like:

memcpy(lpszBuf,tempShmEntry.shmLpMapAddress,bufLength); {where tempShmEntry.shmLpMapAddress is the address of the base of the buffer}

I have written the information in lpszBuf to a file from the C dll and it is all there. There seems to be a problem between C an Perl however. Does anyone have any ideas?
Thanks in advance,
Mike

20040204 Edit by Corion Added code tags


In reply to Problems Passing String Argument With Nulls From C To Perl by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.