简体   繁体   English

从另一个dll内的dll获取字符串

[英]get string from a dll inside another dll

Here is the case: 就是这种情况:

I made a dll with a function1 inside as below: 我制作了一个带有function1的dll,如下所示:

int function1( char *inVal, char *outVal)
{
....
strcpy(outVal,dn.commonname.c_str());
}

in the last line outVal is pointed to dn.commonname which is a string. 在最后一行中,outVal指向一个字符串dn.commonname。

I loaded this dll in another dll with LoadLibrary successfully. 我已使用LoadLibrary成功将此dll加载到另一个dll中。 In second dll I have: 在第二个dll中,我有:

int function1(string inval, string &outVal)
{   
    typedef int (WINAPI *func1Ptr)(char *, char *);


        char outValPtr[128] = {0};
        int retVal = func1Lnk((char *)inVal.c_str(), outValPtr);
        string outVal = outValPtr;  
 }

Now, I am loading second dll in my code and call fnuction1, but when I check the second argument of the function, I get NULL. 现在,我正在代码中加载第二个dll并调用fnuction1,但是当我检查该函数的第二个参数时,我得到了NULL。

Can anyone shed the light on this? 谁能阐明这一点?

EDIT-1 编辑1

I changed my code to: 我将代码更改为:

int function1(string inVal, string &outVal)
{   
    typedef int (WINAPI *func1Ptr)(char *, char *);


        char outValPtr[128] = {0};
        int retVal = func1Lnk((char *)inVal.c_str(), outValPtr);
        outVal = outValPtr;  
 }

But the problem did not solve. 但是问题没有解决。 any clue? 有什么线索吗?

You declare a local variable shadowing the argument: 您声明一个局部变量以使参数变暗:

string outVal = outValPtr;

Well, it's almost shadowing the argument, because the spelling of the names are different. 好吧,这几乎使论点难以理解,因为名称的拼写是不同的。 A variable named outVal is not the same variable as one named outval . 名为outVal的变量与名为outval变量outval Names in C++ are case-dependent. C ++中的名称取决于大小写。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM