@Remy
I removed all the references to "__stdcall" and uncommented the "extern "C" code in the C++ dll, so that the function should be now exported as "_add_code".
I changed the DLL declaration in:
<DllImport("MyDll.dll", EntryPoint:="_add_code")>
Private Shared Function _add_code(ByVal text As String) As <MarshalAs(UnmanagedType.BStr)> String
End Function
Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim foo As String = _add_code("ppp")
End Sub
Noting changes, i get alway the error "System.EntryPointNotFoundException: Could not find entry point with name '_add_code' in the DLL. The Entry point is not found, so I think that eventual errors related to Strings still have to be evaluated.
Folowing your suggestion I also tried a dump to get an Export table by VS command line, and I obtain the follw answer, that confirms that the function is exported as "_add_code". So the question: "Why I can't access to it from VB??"
Microsoft (R) COFF/PE Dumper Version 14.44.35217.0
Copyright (C) Microsoft Corporation. All rights reserved.
Dump of file MyDll.dll
File Type: DLL
Section contains the following exports fory MyDll.dll
00000000 characteristics
FFFFFFFF time date stamp
0.00 version
1 ordinal base
1 number of functions
1 number of names
ordinal hint RVA name
1 0 00001210 add_code = _add_code
Summary
1000 .data
1000 .rdata
1000 .reloc
1000 .rsrc
2000 .text