我有一个应用程序调用并传递参数到C ++ DLL。我还有一个用vb.net编写的单独的可执行文件,我想将参数从c ++ dll传递给vb.net可执行文件。我已经阅读了很多关于此的内容,并且无法弄清楚实现这一目标的最佳方法是什么。
我不一定需要特定的代码,只需在正确的方向上轻推就行了。
这是c ++ dll,我想在我的vb.net应用程序中使用状态结构。
#include "user.h"
#include <windows.h>
#include <atlstr.h>
#include <conio.h>
/////////////////////////////////////
//card macros
#define RANK(c) ((c>>4)&0x0f)
#define SUIT(c) ((c>>0)&0x0f)
#define ISCARDBACK(c) (c==0xff)
#define ISUNKNOWN(c) (c==0)
/////////////////////////////////////
////////////////////////////////////
//consecutive states
holdem_state m_holdem_state[256];
unsigned char m_ndx;
////////////////////////////////////
p_getsym_t p_get_symbol;
double getsym( int chair, const char* name, bool& iserr )
{
return (*p_get_symbol)(chair,name,iserr);
}
double getsym( const char* name )
{
bool iserr;
int mychair = (int) getsym(0,"userchair",iserr);
return getsym(mychair,name,iserr);
}
double process_query( const char* pquery )
{
if (pquery==NULL)
return 0;
if (strncmp(pquery,"dll$test",8)==0)
return getsym("random");
if (strncmp(pquery,"dll$spend",9)==0)
return getsym("f$spend");
if (strncmp(pquery,"dll$recurse",11)==0)
return getsym("dll$mynumber");
if (strncmp(pquery,"dll$mynumber",12)==0)
return 12345.67;
if (strncmp(pquery,"dll$complex",11)==0)
return getsym("f$spend/25 * 1.1");
return 0;
}
double process_state( holdem_state* pstate )
{
if (pstate!=NULL) { m_holdem_state[ (++m_ndx)&0xff ] = *pstate; }
_cprintf("state: %d\n", m_ndx&0xff);
return 0;
}
/////////////////////////////////////////////////////
// user.dll entry point
/////////////////////////////////////////////////////
USERDLL_API double process_message (const char* pmessage, const void* param)
{
if (pmessage==NULL) { return 0; }
if (param==NULL) { return 0; }
if (strcmp(pmessage,"state")==0)
{
holdem_state *state = (holdem_state*) param;
// CString s;
// s.Format("<%s>\nPOTS: %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f\nCOMMON: %d %d %d %d %d\n%d %d %d\n<%s> %d %.2f %d",
// state->m_title,
// state->m_pot[0], state->m_pot[1], state->m_pot[2], state->m_pot[3], state->m_pot[4],
// state->m_pot[5], state->m_pot[6], state->m_pot[7], state->m_pot[8], state->m_pot[9],
// state->m_cards[0], state->m_cards[1], state->m_cards[2], state->m_cards[3], state->m_cards[4],
// state->m_is_playing, state->m_is_posting, state->m_dealer_chair,
// state->m_player[4].m_name, state->m_player[4].m_name_known, state->m_player[4].m_balance, state->m_player[4].m_balance_known);
// MessageBox(NULL, s, "state", MB_OK);
return process_state( (holdem_state*)param );
}
if (strcmp(pmessage,"query")==0)
{
// MessageBox(NULL, (LPCSTR) param, "query", MB_OK);
return process_query( (const char*)param );
}
if (strcmp(pmessage,"pfgws")==0)
{
// MessageBox(NULL, "pfgws", "MESSAGE", MB_OK);
p_get_symbol = (p_getsym_t)param;
return 0;
}
if (strcmp(pmessage,"event")==0 && strcmp((const char *) param, "load")==0)
{
// MessageBox(NULL, "event-load", "MESSAGE", MB_OK);
}
if (strcmp(pmessage,"event")==0 && strcmp((const char *) param, "unload")==0)
{
// MessageBox(NULL, "event-unload", "MESSAGE", MB_OK);
}
return 0;
}
/////////////////////////////////////////////////////
BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
AllocConsole();
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
case DLL_PROCESS_DETACH:
FreeConsole();
break;
}
return TRUE;
}
答案 0 :(得分:0)
extern "C" __declspec(dllexport) holdem_state* getHoldemState() { return &m_holdem_state; }
换句话说,您无法直接共享结构。您需要生成一个将返回值的导出。