Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing parameter to dll in VC++

Status
Not open for further replies.

Iverson3

Programmer
Aug 6, 2004
10
CA
HI,

I encountered a problem while I try to pass a char* object to a class method wrapped in a dll in VC++.

In the exe file, I have the following line

char List[255] = "hi";
vv Connection; // object declaration
//calling the function
Connection.UpdateList(char* ID, char*List);
ccout << List << endl;

In the dll file, I tried to put in either of the following lines in the class method UpdateList:

bool vv::Update(char* ID, char* List) {
.
.
.

case 1: std::streamstring S;
S << "x";
S >> List

case 2: List = "wa";
std::cout << List << std::endl;

}

With the code of Case 1, I got an error with memory stuff at runtime, but no compilation error. It seems like I cant store the value "x" into List.

With the code of Case 2, List store the value of "wa" while in the class method function, but when it returns from the dll function, it stores the value of "hi".

So I am just wondering how should I deal with character pointer object while passing it back and forth between exe and dll files?

Thanks a lot for the hlep in advance,

kim
 
Dont know about case 1, but in case 2 you should use
strcpy(List, "wa");
Simply assigning like
List = "wa";
destroys previous value of parameter (pointer to array List[255]) assigning to it new value of pointer to literal string "wa".
 
What is it: std::streamstring? std::strstream?
Are you sure that S << "x" or "...." with length > sizeof of List? If so, you can overwrite List[255] with a very unsafe (strstream;) S >> List...
 
i see, thanks for all the help =)

Note: case 1 was stringstream, sorry for the typo

However, I did try to use Strcpy function in both cases to store the values in C character array. but I get runtime memory problem with the method suggested. I believe it's the same problem with case 1, though by using different method to try to store a value in List, but the memory just could not be written.

I am not sure whether this is a more fundamental problem where a memory address cant be passed from exe to dll, or it's only passed as read-only somehow.
 
sorry, you were actually right.

I just found that I still had line of

List = " " ;

embedded somewhere down in the code, which triggered the problem,
once this line is removed, everything just worked perfectly.

thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top