PDA

Click to See Complete Forum and Search --> : Passing strings to a VB Activex DLL from C.


chris_s_p_mann
Mar 15th, 2001, 04:17 AM
Does anyone know how to pass a string from a C application to an activex DLL written in VB? - I have managed to pass strings accross and display them in the VB activex DLL, but I need to be able to modify the value in the DLL and have the change reflected in the original variable in the C application. (ie) I want to pass the string byRef, not byVal.

When I try, I just get ???????? turn up as the message in the VB DLL.

If anyone knows how to do this, please let me know and ideally, include a couple lines of example code on the 'C' side of it. - I am getting more and more frustrated with trying to understand all these different string types that are required within C to do this. (eg) char, bstr_t and BSTR.

Thanks.

tumblingdown
Mar 15th, 2001, 09:08 PM
use a BSTR, and i don't think you'll be able to really pass it byref. Try making it the reutrn of a function.



td.

kdx
Mar 16th, 2001, 01:24 AM
Use Cstring


BSTR CKSockCtrl::LocalIPAddress()
{
CString strResult;
HOSTENT *phe;
WSADATA WSAData;

char Buffer[16];

if (WSAStartup(MAKEWORD(1,1), &WSAData))
strResult = "Error";

if ((phe = gethostbyname("")) == NULL)
strResult = "Error";

wsprintf(Buffer, "%u.%u.%u.%u",
(unsigned char) phe->h_addr_list[0][0],
(unsigned char) phe->h_addr_list[0][1],
(unsigned char) phe->h_addr_list[0][2],
(unsigned char) phe->h_addr_list[0][3]);

strResult = Buffer;

return strResult.AllocSysString();
}

chris_s_p_mann
Mar 16th, 2001, 03:21 AM
Thanks for the replies.

The problem is, that I need to return TRUE / FALSE as success or failure of the function. But, if successful then I also need to return a number of strings. The most logical way to do this would be to pass byRef the variables that will need updating.

Does anyone know if this is definately not possible from C calling a VB ActiveX DLL?