Last post Jan 13, 2011 03:00 AM by Shengqing Yang - MSFT
Jan 08, 2011 06:18 AM|mlov83|LINK
hope someone can lend me a quick hand.
Im trying to write a simple c++ dll and then reference it in my vb form app however im having a hell of a time doing so.
i followed this tutorial
but im getting an error when i call the c++ function in vb.net
here is the c++ code
LPCSTR DisplayStringByVal(LPCSTR pszString)
return "Hallo apa kabar ";
void ReturnInParam(int* pnStan, char** pMsg)
char text = "Hallo ";
*pnStan = *pnStan + 5;
buffer = (long *)calloc(sizeof(text)+sizeof(*pMsg), sizeof( char ) );
*pMsg = (char *)buffer;
// do not free the buffer, because it will be used by the caller
// free( buffer );
here is the vb .net code
Public Class Form1
<DllImport("C:\Documents and Settings\JAM3\My Documents\Visual Studio 2008\Projects\TestDLL\Debug\TestDll.dll", CallingConvention:=CallingConvention.Cdecl)> _
Private Shared Sub ReturnInParam(ByRef Stan As Integer, _
ByRef Message As String)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Num As Integer = 8
Dim Message As String = "Harun"
i a runt time error saying "run-time check failure #2 - stack around the variable 'name' was corrupted"
can anyone please offer any suggestions. i would greatly appreciated.
Jan 08, 2011 01:51 PM|mlov83|LINK
bump any ideas guys?
Jan 13, 2011 03:00 AM|Shengqing Yang - MSFT|LINK
It is so hard to clear this issue within a few words. Managed and Unmanaged Code Interoperability is a huge topic and I would like to suggest you having a look at this article:
Some more references are as follows: