C++ dll variable to vb.net exe



我有一个应用程序,它调用参数并将其传递给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: %dn", 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 %.2fnCOMMON: %d %d %d %d %dn%d %d %dn<%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;
}
extern "C" __declspec(dllexport) holdem_state* getHoldemState() { return &m_holdem_state; }

换句话说,您不能直接共享结构。 您需要生成将返回值的导出。

相关内容

  • 没有找到相关文章

最新更新