Click here to Skip to main content
15,914,905 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
AnswerRe: Interview questions for web developer Pin
Ennis Ray Lynch, Jr.4-Feb-10 11:10
Ennis Ray Lynch, Jr.4-Feb-10 11:10 
AnswerRe: Interview questions for web developer Pin
Not Active4-Feb-10 11:26
mentorNot Active4-Feb-10 11:26 
GeneralRe: Interview questions for web developer Pin
Pete O'Hanlon5-Feb-10 4:51
mvePete O'Hanlon5-Feb-10 4:51 
AnswerRe: Interview questions for web developer Pin
Dave Kreskowiak4-Feb-10 12:51
mveDave Kreskowiak4-Feb-10 12:51 
AnswerRe: Interview questions for web developer Pin
Rozis4-Feb-10 13:29
Rozis4-Feb-10 13:29 
QuestionFile associations in .Net framework library Pin
Edward Diener4-Feb-10 7:39
Edward Diener4-Feb-10 7:39 
AnswerRe: File associations in .Net framework library Pin
Dave Kreskowiak4-Feb-10 7:47
mveDave Kreskowiak4-Feb-10 7:47 
QuestionAccessing DLL C++ with string pointer using VB.NET Pin
TremaHD4-Feb-10 7:00
TremaHD4-Feb-10 7:00 
Hi,

I want to use a simple function in a C++ DLL. The declaration in the header file for that function is:
#define API_SPEC     __declspec(dllexport)
void API_SPEC API_getApiVersion (std::wstring *version) //[out] API release ID

That function receive a pointer to a UNICODE string and will put the release ID of that API in that string. (correct me if i'm wrong!)

I use VB.Net to call that DLL and read the content of that string. Here is my code:
Public Class Form1
    <DllImport("C:\Api.dll", EntryPoint:="?API_getApiVersion@@YAXPAV?$basic_string@GU?$char_traits@G@std@@V?$allocator@G@2@@std@@@Z", CallingConvention:=CallingConvention.ThisCall, CharSet:=CharSet.Unicode)> _
    Public Shared Sub test(ByVal version As String)
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim theVersion As String = New String(" "c, 20)
        Call test(theVersion )
        MessageBox.Show(theVersion)
    End Sub
End Class

When I run that code I get:"AccessViolationException was unhandled."

My question: what is wrong with my code? I even try to use a stringbuilder instead of string type but I got the same error.

Thanks for your help!
AnswerRe: Accessing DLL C++ with string pointer using VB.NET Pin
Luc Pattyn4-Feb-10 7:30
sitebuilderLuc Pattyn4-Feb-10 7:30 
GeneralRe: Accessing DLL C++ with string pointer using VB.NET Pin
TremaHD4-Feb-10 12:38
TremaHD4-Feb-10 12:38 
AnswerRe: Accessing DLL C++ with string pointer using VB.NET Pin
Richard MacCutchan4-Feb-10 8:42
mveRichard MacCutchan4-Feb-10 8:42 
GeneralRe: Accessing DLL C++ with string pointer using VB.NET Pin
TremaHD4-Feb-10 12:36
TremaHD4-Feb-10 12:36 
GeneralRe: Accessing DLL C++ with string pointer using VB.NET Pin
Richard MacCutchan4-Feb-10 12:50
mveRichard MacCutchan4-Feb-10 12:50 
GeneralRe: Accessing DLL C++ with string pointer using VB.NET Pin
TremaHD4-Feb-10 13:06
TremaHD4-Feb-10 13:06 
GeneralRe: Accessing DLL C++ with string pointer using VB.NET Pin
Richard MacCutchan4-Feb-10 21:53
mveRichard MacCutchan4-Feb-10 21:53 
GeneralRe: Accessing DLL C++ with string pointer using VB.NET Pin
MicroVirus5-Feb-10 11:09
MicroVirus5-Feb-10 11:09 
GeneralRe: Accessing DLL C++ with string pointer using VB.NET Pin
TremaHD5-Feb-10 14:27
TremaHD5-Feb-10 14:27 
GeneralRe: Accessing DLL C++ with string pointer using VB.NET Pin
Richard MacCutchan5-Feb-10 22:40
mveRichard MacCutchan5-Feb-10 22:40 
GeneralRe: Accessing DLL C++ with string pointer using VB.NET Pin
MicroVirus8-Feb-10 0:31
MicroVirus8-Feb-10 0:31 
GeneralRe: Accessing DLL C++ with string pointer using VB.NET Pin
Richard MacCutchan8-Feb-10 1:55
mveRichard MacCutchan8-Feb-10 1:55 
GeneralRe: Accessing DLL C++ with string pointer using VB.NET Pin
Luc Pattyn4-Feb-10 12:56
sitebuilderLuc Pattyn4-Feb-10 12:56 
GeneralRe: Accessing DLL C++ with string pointer using VB.NET Pin
Richard MacCutchan4-Feb-10 21:54
mveRichard MacCutchan4-Feb-10 21:54 
GeneralRe: Accessing DLL C++ with string pointer using VB.NET Pin
Luc Pattyn4-Feb-10 23:32
sitebuilderLuc Pattyn4-Feb-10 23:32 
GeneralRe: Accessing DLL C++ with string pointer using VB.NET Pin
Richard MacCutchan5-Feb-10 0:42
mveRichard MacCutchan5-Feb-10 0:42 
GeneralRe: Accessing DLL C++ with string pointer using VB.NET Pin
TremaHD5-Feb-10 2:26
TremaHD5-Feb-10 2:26 

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.