int _stdcall of_get_vip_info_test(const char* vipno, char* ret_vipxx[15], char* errMsg)
{
int err = 0;
int argc;
char **argv = {0x00};  ofstream outClientFile4("of_get_vip_log.txt", ios::app);
 outClientFile4<<"this is a test" <<endl;  outClientFile4<<vipno<<endl;
const char *addr = ".\\xl_card.ini";
char url[50],name[50],pass[50],qybh[50],vip_qybh[50],ping[50],application[50];
GetPrivateProfileString("Easerver", "location", NULL, url, sizeof(url),addr);
GetPrivateProfileString("Easerver", "userID", NULL, name, sizeof(name),addr); 
GetPrivateProfileString("Easerver", "password", NULL, pass, sizeof(pass),addr); 
GetPrivateProfileString("configure","qybh", NULL, qybh, sizeof(qybh),addr);
GetPrivateProfileString("configure","vip_qybh", NULL, vip_qybh, sizeof(vip_qybh),addr);
GetPrivateProfileString("Easerver", "ping", NULL, ping, sizeof(ping),addr);
GetPrivateProfileString("Easerver", "application", NULL, application, sizeof(application),addr); WSAData wsaData;
if (WSAStartup(MAKEWORD(1, 1), &wsaData) != 0) {
err = -1;
strcpy(errMsg,"网络连接失败");
        return err;
}
char* errorMsg = (char*)malloc(sizeof(char)*100);
int Error = doit(ping, errorMsg);
if(Error != 0) {
err = Error;
strcpy(errMsg,errorMsg);
free(errorMsg);
return err;
}
// 释放Winsock资源
free(errorMsg);
    WSACleanup();
outClientFile4<<"this is a test2"<<endl; try
{
com_message* pMsg;

    char* manager_url = url;
    CORBA::ORB_var orb = CORBA::ORB_init(argc, argv, 0);
    CORBA::Object_var obj;
    obj = orb->string_to_object(manager_url);
    SessionManager::Manager_var manager = SessionManager::Manager::_narrow(obj);     if (CORBA::is_nil(manager)) 
{
    err = -1;
strcpy(errMsg,"Error: Null SessionManager::Manager instance. Exiting.");
    return err;
}
    SessionManager::Session_var session = manager->createSession(name, pass);
    if (CORBA::is_nil(session))
{
    err = -1;
strcpy(errMsg,"Error: Null session. Exiting.");
    return err;
}
    strcat(application,"com_card_ot");
    com_card_ot_var pComp = com_card_ot::_narrow(Object_var(session->create(application)));     vip_info_str a_ret_vipxx; outClientFile4<<"this is a test3"<<endl;     pMsg = pComp->of_get_vip_info(vipno, a_ret_vipxx, (const char*)vip_qybh);
outClientFile4<<pMsg->id<<endl;

    if(pMsg->id == 0) //执行成功
{
    err = pMsg->id;
outClientFile4<<"OK"<<endl;

           strcpy_s(ret_vipxx[0], (const char*)a_ret_vipxx.viptype);
outClientFile4<<ret_vipxx[0]<<endl;
        strcpy(ret_vipxx[1], (const char*)a_ret_vipxx.vipname);
outClientFile4<<ret_vipxx[1]<<endl;
        strcpy(ret_vipxx[2], (const char*)a_ret_vipxx.vname);
outClientFile4<<ret_vipxx[2]<<endl;
        strcpy(ret_vipxx[3], (const char*)a_ret_vipxx.vipno);
        strcpy(ret_vipxx[4], (const char*)a_ret_vipxx.point);
        strcpy(ret_vipxx[5], (const char*)a_ret_vipxx.jkrq);
        strcpy(ret_vipxx[6], (const char*)a_ret_vipxx.yxq);
        strcpy(ret_vipxx[7], (const char*)a_ret_vipxx.ljxfje);
outClientFile4<<ret_vipxx[7]<<endl;
        strcpy(ret_vipxx[8], (const char*)a_ret_vipxx.vipid);
        strcpy(ret_vipxx[9], (const char*)a_ret_vipxx.level_id);
        strcpy(ret_vipxx[10], (const char*)a_ret_vipxx.level_name);

strcpy(errMsg,"成功");

}
    else
{
            err = pMsg->id;
    strcpy(errMsg,pMsg->txt);
}

return err;
}
catch( CORBA::OBJECT_NOT_EXIST cone )
{
err = -1;
        strcpy(errMsg,"Error: CORBA OBJECT_NOT_EXIST exception. Check the server log file for more information. Also verify that the 'com_card_ot' component has been created properly in Jaguar Manager.");
    return err;
}
catch(CORBA::NO_PERMISSION npe)
{
err = -1;
strcpy(errMsg,"Error: CORBA NO_PERMISSION exception. Check whether login authentication is enabled for your server and whether the component has restricted access. If so edit the source file to use a valid user name and password.");
return err;
}
catch( CORBA::INV_OBJREF cio )
{
err = -1;
strcpy(errMsg,"Error: CORBA INV_OBJREF exception.");
return err;
}
catch ( CORBA::COMM_FAILURE ccf )
{
err = -1;
strcpy(errMsg,"Error: CORBA COMM_FAILURE exception. Check that the specified host and IIOP port number are correct and that the server is running.");
return err;
}
catch( CORBA::OBJ_ADAPTER )
{
err = -1;
strcpy(errMsg,"Error: CORBA OBJ_ADAPTER");
return err;
}
catch( CORBA::SystemException cse )
{
err = -1;
strcpy(errMsg,"Error: CORBA System Exception. Check that the server hostname and IIOP port are specified correctly, and check the server's error log for more information.");
return err;
}
}

解决方案 »

  1.   

    char* ret_vipxx[15]  改成char* ret_vipxx
      

  2.   

    这是dll的源码,改不了,C#怎么取这个字符串数组地址
      

  3.   

    char* ret_vipxx[15] 是个长度为15的char* 数组
    char* -> stringbuilder
    char* [15] -> stringbuilder[15]
    stringbuilder 需要根据c dll要求先申请空间,后使用
    还有个需要注意
    c#默认的是Unicode,而c dll大多采用Ansi
      

  4.   

    跟我之前调的一个dll的参数很相似,试试吧。
    [DllImport("xxx.dll")]
    public static extern int of_get_vip_info_test(ref string vipno, [MarshalAs(UnmanagedType.VBByRefStr)]ref string ret_vipxx, ref string errMsg);string ret_vipxx = "***************";    //要够15个字符
    char* ret_vipxx[15]   15个字符,传参字符串要够15个,如果返回的字符串不足15个后面的会补\0