VC++ returns value to VB (Dll)

F

floydus

Return a CString to VB and use it in VB...

I badly need to send text string from VC++(Take note that the type of
my variable is CString !), I'm so disappointed, I tried like 4-5
approches, nothing works !
Please help me before I put that computer into garbage, it's been 2
weeks without having found.


Here is my VC++ function.
I'm able to call it, but the best I got is the first character only...
Anyway..
Have a look.
I cannot change the type from CString to something else, I have to use
CString (Supplied Api...)
VC++
///////////////////////////////////////////////////////////////////////
Should *CString* be the returned type ???????

CString _stdcall SearchLast(int chn)
{
(strTmp2 declared as CString outside)
strTmp2="Nothing";
.......some other code here........
::DxSearchStart( m_hServer, &SearchInfo );
AfxMessageBox(strTmp2);
return strTmp2;

}

VB CODE is below...

////////////////////////////////////////////////////////////////////////

Private Declare Function SearchLast Lib "PelcoDLL.dll" (ByVal Channel
As Integer) As String

Private Sub Command2_Click()
Dim i As String
i = SearchLast(0)
MsgBox i
End Sub
 
D

David Lowndes

I badly need to send text string from VC++(Take note that the type of
my variable is CString !)

Here's an example of returning a string to VB. Note it doesn't use
CString - VB cannot use a CString.


VB DEFINITIONS:

Declare Function fnReturnString Lib "VBDLLTest.dll" (ByVal x As
String) As String

And the CPP:

#define VBDLLTEST_API __declspec(dllexport)

extern "C"
{
//an example of returning a string from a C DLL routine
VBDLLTEST_API BSTR __stdcall fnReturnString( LPCSTR s1 )
{
BSTR bstr;
bstr = SysAllocStringByteLen( "Hello there dear world",
sizeof("Hello there dear world")-1 );

return bstr;
}

Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top