Click here to Skip to main content
15,888,113 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
I have another program that will sent strings to another application. This application will load my dll as plugin, how do I receive the strings with my dll using WM_COPYDATA ? how do I declare WM_COPYDATA inside my dll?

C++
BOOL APIENTRY DllMain (HINSTANCE hInst,DWORD reason,LPVOID reserved )
{
switch (reason)
    {
		case DLL_PROCESS_ATTACH:
			 CreateThread(0, 0, (LPTHREAD_START_ROUTINE)main, 0, 0, 0);
		break;
    }

    return TRUE;
}


What I have tried:

I don't know how to use WM_COPYDATA inside the dll.
Posted
Updated 13-Apr-16 3:00am
Comments
Richard MacCutchan 13-Apr-16 8:06am    
You cannot send messages to a DLL as it does not have a message pump. You need to use some other mechanism.
Sergey Alexandrovich Kryukov 13-Apr-16 8:51am    
It makes no sense. If you develop plug-in, develop appropriate plug-in interfaces.
—SA

To pass a string to a DLL just pass a const char* or const wchar_t* pointer when calling a DLL function. The DLL function may then create a local copy of the string if necessary.

Sending WM_COPYDATA messages requires a destination window handle and a message loop which may be not present in a DLL.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 13-Apr-16 9:02am    
Sure, a 5.
And, on the positive side, I depicted the whole brief sketch of proper plug-in architecture in Solution 2.
—SA
Jochen Arndt 13-Apr-16 9:24am    
Thank you Sergey.
My 5 too for your solution about plug-ins.
Sergey Alexandrovich Kryukov 13-Apr-16 9:31am    
Thank you, Jochen.
—SA
Please see my comment and Solution 1, which correctly explains another reason why it all makes no sense.

If you define the system with plug-ins, first define some plug-in interfaces. Plug-in model is interesting. Normally, the host application provides its own plug-in interface which each plug-in can use in its implementation, and expects all plug-ins to implement one or more interfaces, which are fixed; you can consider then as "contract" between the host application and plug-in modules.

I would strongly advice to make plug-in DLL "entry-free", or, better, the architecture to be "entry-agnostic". I would advice to export only one method from all plug-in, such as "get interface", which returns the instance of an object implementing the plug-in interface. Actually, you can develop the system implementing more than one plug-in in a single DLL module, through some interface listing several objects each implementing its own plug-in interface.

By "interface", you can use, say, a class without data with pure-virtual functions (COM interfaces were actually modeled after such structures), and the "implementation" would be a class overriding all these functions.

Now, when you build appropriate plug-in architecture, you can pass anything via the interface functions in any directions, strings or anything else.

—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900