The following are the procedures I use to set and get from the shared memory area. I threw the structure in as a reference. Ignore the red +s as they indicate a line wrap. -Mike
//*********************************************************** //* * //* Structure Definitions * //* * //*********************************************************** struct shmInfoEntry { char shmBufferName[25]; DWORD shmBufferSize; DWORD shmDataSize; HANDLE shmHMapFile; LPVOID shmLpMapAddress; }; //*********************************************************** //*Name: SetSharedMem * //*Function: SetSharedMem sets the value of the shared * //* memory area reference by shareIndex * //*Return Vals: 0 = Operation Failed * //* 1 = Operation Succeeded * //*********************************************************** int __export __stdcall SetSharedMem(const int shareIndex, const void* +lpszBuf, const DWORD bufLength) { LPVOID recordOffset; struct shmInfoEntry tempShmEntry; // DEGUG FOR SEEING IF lpszBuf is writing out the proper stuff // FILE *crapfile; // // // Write out file // crapfile=fopen("crapfile.txt","wb"); // fwrite(lpszBuf,bufLength,1,crapfile); // fclose(crapfile); if (shareIndex > lastShmIndex) { // Have To Use A Existing Share return 0; } // Get Record Offset To Struct Of Info recordOffset = (DWORD) lpvMem + (sizeof(int) + (shareIndex * sizeO +fInfoStruct)); // Copy Struct From Shared Memory memcpy(&tempShmEntry,recordOffset,sizeOfInfoStruct); if (bufLength > tempShmEntry.shmBufferSize) { //NOTE: THIS IS BAD, RESIZE BUFFER OR FAIL return 0; } // Set Data Size tempShmEntry.shmDataSize = bufLength; // Save Data Size memcpy(recordOffset,&tempShmEntry,sizeOfInfoStruct); // lpMapAddress should be the first memory byte of the shared memo +ry struct memcpy(tempShmEntry.shmLpMapAddress,lpszBuf,bufLength); return 1; } //*********************************************************** //*Name: GetSharedMem * //*Function: GetSharedMem gets the value of the shared * //* memory area reference by shareIndex * //*Return Vals: 0 = Operation Failed * //* 1 = Operation Succeeded * //*********************************************************** int __export __stdcall GetSharedMem(const int shareIndex,void* lpszBuf +, const DWORD bufLength) { LPVOID recordOffset; struct shmInfoEntry tempShmEntry; // FILE *crapfile; if (shareIndex > lastShmIndex) { return 0; } // Get Record Offset To Struct Of Info recordOffset = (DWORD) lpvMem + (sizeof(int) + (shareIndex * sizeO +fInfoStruct)); // Copy Struct From Shared Memory memcpy(&tempShmEntry,recordOffset,sizeOfInfoStruct); if (bufLength > tempShmEntry.shmBufferSize) { //NOTE: THIS IS BAD, RESIZE BUFFER OR FAIL return 0; } // Grab Stuff Out Of Buffer memcpy(lpszBuf,tempShmEntry.shmLpMapAddress,bufLength); // Debugging what should be returned // crapfile=fopen("crapfile.txt","wb"); // fwrite(lpszBuf,bufLength,1,crapfile); // fclose(crapfile); return 1; }

In reply to Re: Re: Problems Passing String Argument With Nulls From C To Perl by lamberms
in thread 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.