15,473
社区成员




CDLLTestApp theApp;
int n_COMPort = 0;
// CDLLTestApp initialization
BOOL CDLLTestApp::InitInstance()
{
CWinApp::InitInstance();
return TRUE;
}
extern "C" _declspec(dllexport) void SetCOMPort(int nCOMPort)
{
n_COMPort = nCOMPort;
}
extern "C" _declspec(dllexport) int GetCOMPort()
{
GetSelfModuleHandle();
return n_COMPort;
}
namespace AppMain
{
public class DLLTestHelper
{
[DllImport("DllTest.dll", EntryPoint = "SetCOMPort")]
public static extern void _SetCOMPort(int nCOMPort);
[DllImport("DllTest.dll", EntryPoint = "GetCOMPort")]
public static extern int _GetCOMPort();
public void SetCOMPort(int nCOMPort)
{
_SetCOMPort(nCOMPort);
}
public int GetCOMPort()
{
return _GetCOMPort();
}
}
}
DLLTestHelper _Helper1 = new DLLTestHelper();
_Helper1.SetCOMPort(1);
DLLTestHelper _Helper2 = new DLLTestHelper();
_Helper1.SetCOMPort(2);
int n1 = _Helper1.GetCOMPort();
int n2 = _Helper2.GetCOMPort();
static class ComPort
{
private static int n_COMPort;
public static void SetCOMPort(int nCOMPort)
{
n_COMPort = nCOMPort;
}
public static int GetCOMPort()
{
return n_COMPort;
}
}
class DLLTestHelper
{
public void SetCOMPort(int nCOMPort)
{
ComPort.SetCOMPort(nCOMPort);
}
public int GetCOMPort()
{
return ComPort.GetCOMPort();
}
}