Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / VB

Export C++ to VB.NET

4.25/5 (6 votes)
28 Mar 2010CPOL 1  
If you want to export strings in C++ to VB.NET, build your function like this:BSTR __stdcall expfun(void){ char* cp_test = Hi World!; CString cs_test; cs_test.AppendFormat(L%s, cp_test); return cs_test.AllocSysString();}and in VB.NET:Imports...
If you want to export strings in C++ to VB.NET, build your function like this:

C++
BSTR __stdcall expfun(void)
{
   char* cp_test = "Hi World!";

   CString cs_test;
   cs_test.AppendFormat(L"%s", cp_test);

   return cs_test.AllocSysString();
}


and in VB.NET:

VB
Imports System.Runtime.InteropServices
.
.
.
<DllImport("dll_path", CallingConvention:=CallingConvention.StdCall, CharSet:=CharSet.None)> _
Public Shared Function expfun() As String
End Function

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)