Passing a structure to a DLL
Posted: Fri Mar 18, 2011 6:54 am
I'm wanting to split my monolithic program into two or more compilable units, so I'm planning to keep all the GUI handling in my main program and place the bulk of the processing logic into a DLL. An issue I'm concerned about with this approach is that I have some large structures and arrays that I need to access from both the program and the DLL. Only the DLL will update this information, but the GUI program needs to be able to read it.
So in the GUI program, I may send a request to the DLL to give me the details of a cue, held in a structured variable in the DLL. All the structure definitions are held in .pbi include file which is included in both the GUI program and the DLL, so I can guarantee compatibility.
My question is, how can I pass this structured variable from the DLL to the GUI program? I can see that I could get the DLL to return a memory pointer, but just doing CopyMemory into an equivalent structured variable in the GUI program I don't think will work, especially regarding string variables within the structure. I've searched the Forum and did find some info about the Windows function CreateFileMapping, in the topic Simple shared memory using file maps on Windows. Is this the way to go or is there a better solution?
So in the GUI program, I may send a request to the DLL to give me the details of a cue, held in a structured variable in the DLL. All the structure definitions are held in .pbi include file which is included in both the GUI program and the DLL, so I can guarantee compatibility.
My question is, how can I pass this structured variable from the DLL to the GUI program? I can see that I could get the DLL to return a memory pointer, but just doing CopyMemory into an equivalent structured variable in the GUI program I don't think will work, especially regarding string variables within the structure. I've searched the Forum and did find some info about the Windows function CreateFileMapping, in the topic Simple shared memory using file maps on Windows. Is this the way to go or is there a better solution?