Question

'm new to C++ so still trying to get my head around the code so sorry for sounding stupid!

I'm making changes to some existing code.

The old code is calling the below function where the cbDataSize is being determined by sizeof(MyStruct)

BOOL WINAPI WriteMsgQueue(HANDLE hMsgQ, LPVOID lpBuffer, DWORD cbDataSize, DWORD dwTimeout, DWORD dwFlags);

The change I made was to add another Struct within the Struct MyStruct so that it now looks like:

struct MyInnerStruct {
    char myarray[20][256];
    long mycount; 
};

struct MyStruct {
    long value1;
    long value2;
    MyInnerStruct inner;  
};

Below is the call to WriteMsgQueue:

HANDLE requestQueue;
MyStruct myData;
DWORD timeout = 12000;

WriteMsgQueue(requestQueue, &myData, sizeof(myData), timeout, 0);

I am now receiving the System Error 122 - ERROR_INSUFFICIENT_BUFFER when the WriteMsgQueue() is being called.

Any help appreciated on how I calculate the correct size?

Was it helpful?

Solution

The queue probably wasn't allocated with enough space to hold your larger structure. You may need to find where the old code creates the queue (via CreateMsgQueue()) and look at the MSGQUEUEOPTIONS struct being passed in. This struct has a cbMaxMessage field which determines the maximum size of a single message. You may need to increase this. Also check the other fields like cbSize, dwMaxMessages etc.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top