Click here to Skip to main content
15,892,480 members
Articles / Programming Languages / Visual Basic
Tip/Trick

Export C++ to VB.NET

Rate me:
Please Sign up or sign in to vote.
4.25/5 (6 votes)
28 Mar 2010CPOL 16.9K   4   2
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)


Written By
Software Developer (Junior)
Turkey Turkey
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 4 Pin
Karay AKAR - Yapar6-Feb-13 3:46
Karay AKAR - Yapar6-Feb-13 3:46 
GeneralRe: My vote of 4 Pin
Ozan Müyesseroğlu10-Feb-13 15:28
Ozan Müyesseroğlu10-Feb-13 15:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.