DLL从另一个应用程序接收字符串 [英] Dll receiving strings from another application

查看:82
本文介绍了DLL从另一个应用程序接收字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有另一个程序将字符串发送到另一个应用程序。这个应用程序将加载我的DLL作为插件,如何使用WM_COPYDATA接收我的DLL的字符串?如何在我的dll中声明WM_COPYDATA?



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?

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;
}





我的尝试:



我不知道如何在dll中使用WM_COPYDATA。



What I have tried:

I don't know how to use WM_COPYDATA inside the dll.

推荐答案

要将字符串传递给DLL,只需传递<$ c $调用DLL函数时,c> const char * 或 const wchar_t * 指针。然后,DLL函数可以在必要时创建字符串的本地副本。



发送 WM_COPYDATA 消息需要目的地窗口句柄和消息循环可能不存在于DLL中。
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.


请参阅我的评论和解决方案1,这正确地解释了为什么这一切都没有意义的另一个原因。


如果使用插件定义系统,首先要定义一些插件接口。插件模型很有趣。通常,主机应用程序提供自己的插件接口,每个插件可以在其实现中使用,并期望所有插件实现一个或多个固定的接口;你可以把它视为主机应用程序和插件模块之间的契约。



我强烈建议让插件DLL免入门,或者,更好的是,该架构是入门不可知的。我建议只从所有插件中导出一个方法,例如get interface,它返回实现插件接口的对象的实例。实际上,您可以在单个DLL模块中开发实现多个插件的系统,通过一些接口列出几个对象,每个对象实现自己的插件接口。



通过接口,您可以使用没有带纯虚函数的数据的类(COM接口实际上是在这些结构之后建模的),而实现将是一个覆盖所有这些函数的类。



现在,当您构建适当的插件架构时,您可以通过任何方向,字符串或其他任何方式通过接口函数传递任何内容。



-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


这篇关于DLL从另一个应用程序接收字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆