Главная страница | назад





Article #19237: Passing a String from a 16 bit VB app to a 16 bit C .DLL

 Question and Answer Database

FAQ4237C.txt   :Passing a String from a 16 bit VB app to a 16 bit C .DLL
Category   :Miscellaneous
Platform    :Windows 3.1
Product    :BC++4.5x,   BC++5.x,   TC++Win4.5,   

Question:
I have a 16 bit Visual Basic application that I am developing.
I have a 16 bit C DLL that I am also developing.

I need to be able to pass strings back and forth between the two
with the ability to modify the data in either module.

How can I pass the string to the DLL so that the DLL may modify the
sting and VB will see it?

Answer:

In your VB application pass a string by refrence to the DLL.

The function in the DLL will take the string argument as a char**, ie:

void GetString(char **string);

To modify the string in the DLL, derefrence the variable to get access
to the char *, for example to do a string copy:

strcpy(*string, "Right back at you");

On the VB side you will need to make sure that your string is big enough
to hold all of the characers in cluding the null terminator if you are going
to be doing any string manipulations on it like strcpy.

You will then need to manually strip the NULL off the result, or you may use 
memcpy instead of strcpy, but you will have to be careful, ie:

char newstr[] "back to ya";

if (strlen(*string) >= strlen(newstr))
{
   memcpy(*string, strlen(newstr), newstr);
}




12/16/1998 8:56:16 AM
 

Last Modified: 01-SEP-99