共享数据可以实现这个功能. see more. http://www.codeproject.com/dll http://www.codeproject.com/dll/data_seg_share.asp
// test.cpp : Defines the entry point for the DLL application. //#include "stdafx.h" #include "test.h"#pragma data_seg("SharedData") int g_index = 0; // 必须要初始化 #pragma data_seg() #pragma comment(linker,"/section:SharedData,rws")BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: case DLL_THREAD_ATTACH: case DLL_THREAD_DETACH: case DLL_PROCESS_DETACH: break; } return TRUE; } // This is an example of an exported function. TEST_API int fnGet( ) { return g_index; }TEST_API int fnSet(int index) { g_index = index; }
当然可以了,你只要把类放到“共享段”中,不就可以了吗? // test.cpp : Defines the entry point for the DLL application. //#include "stdafx.h" #include "test.h"#pragma data_seg("SharedData") CTest g_test; #pragma data_seg() #pragma comment(linker,"/section:SharedData,rws")BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: case DLL_THREAD_ATTACH: case DLL_THREAD_DETACH: case DLL_PROCESS_DETACH: break; } return TRUE; } // This is an example of an exported function. TEST_API int fnGet( ) { return g_test.getIndex( ); }TEST_API int fnSet(int index) { g_pTest.setIndex(index); }
see more.
http://www.codeproject.com/dll
http://www.codeproject.com/dll/data_seg_share.asp
//#include "stdafx.h"
#include "test.h"#pragma data_seg("SharedData")
int g_index = 0; // 必须要初始化
#pragma data_seg()
#pragma comment(linker,"/section:SharedData,rws")BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
// This is an example of an exported function.
TEST_API int fnGet( )
{
return g_index;
}TEST_API int fnSet(int index)
{
g_index = index;
}
// test.cpp : Defines the entry point for the DLL application.
//#include "stdafx.h"
#include "test.h"#pragma data_seg("SharedData")
CTest g_test;
#pragma data_seg()
#pragma comment(linker,"/section:SharedData,rws")BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
// This is an example of an exported function.
TEST_API int fnGet( )
{
return g_test.getIndex( );
}TEST_API int fnSet(int index)
{
g_pTest.setIndex(index);
}
[email protected]
我使用你的方法想用MDI的VIEW中的函数和变量,但老出异常,如果能帮我找出原因,真是太好了。