Domanda

Here is the case:

I made a dll with a function1 inside as below:

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.

I loaded this dll in another dll with LoadLibrary successfully. In second dll I have:

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.

Can anyone shed the light on this?

EDIT-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?

È stato utile?

Soluzione

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. Names in C++ are case-dependent.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top