Click here to Skip to main content
15,925,505 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Read and compile a stored procedure Pin
Dave Kreskowiak16-Jan-08 4:34
mveDave Kreskowiak16-Jan-08 4:34 
GeneralRe: Read and compile a stored procedure Pin
HenrydeSousa16-Jan-08 7:10
HenrydeSousa16-Jan-08 7:10 
GeneralRe: Read and compile a stored procedure Pin
HenrydeSousa11-Feb-08 14:56
HenrydeSousa11-Feb-08 14:56 
GeneralButton Size in ButtonColumn in DataGridView Pin
ExcelMonkey15-Jan-08 5:50
ExcelMonkey15-Jan-08 5:50 
GeneralRe: Button Size in ButtonColumn in DataGridView Pin
Dave Kreskowiak15-Jan-08 9:22
mveDave Kreskowiak15-Jan-08 9:22 
GeneralConfirm Message in DataGrid Pin
M_Menon15-Jan-08 5:26
M_Menon15-Jan-08 5:26 
GeneralRe: Confirm Message in DataGrid Pin
Dave Kreskowiak15-Jan-08 6:12
mveDave Kreskowiak15-Jan-08 6:12 
GeneralUnmanaged DLLs Pin
Charles Keepax15-Jan-08 2:53
Charles Keepax15-Jan-08 2:53 
Hi,

I have a mostly C++ background and have a small VB.NET problem and was hoping for some advice from you guru's out there in VB land. I am using VS.NET 2002, incase anyone know of a problem with that version.
I am trying to access functions in a unmanaged DLL from a managed VB application. I can get this to work fine until I use a DLL function that has a string as a parameter. When I call a function with a string as a parameter, although the DLL receives the string correcly, the return value of all future DLL calls is garbage. I have created a small sample application (DLL and VB) to demonstrate the problem. I have posted the code in this post (sorry about that but figured it would be nessecary).

Any help would be awesome?

Thanks in Advance,
Charles

Example follows, in the VB application the first two calls to fnTestNumber are handled fine, but the return value from fnTestString and the last fnTestNumber are random.
VB Application:
Imports System.Runtime.InteropServices<br />
<br />
Module Module1<br />
<br />
    <DllImport("TestDLL.DLL", _<br />
    CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.Cdecl)> _<br />
        Function fnTestNumber(ByVal iTest As Long) As Long<br />
    End Function<br />
    <DllImport("TestDLL.DLL", _<br />
    CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.Cdecl)> _<br />
        Function fnTestString(<MarshalAs(UnmanagedType.LPStr)> ByVal szTest As String) As Long<br />
    End Function<br />
<br />
    Sub Main()<br />
        Dim retcode As Long<br />
<br />
        retcode = fnTestNumber(9876)<br />
        retcode = fnTestNumber(7654)<br />
        retcode = fnTestString("DATAFILE1.DAT")<br />
        retcode = fnTestNumber(1234)<br />
    End Sub<br />
<br />
End Module


C++ DLL:
__declspec(dllexport) int fnTestNumber(int iTest)<br />
{<br />
	return iTest;<br />
}<br />
<br />
__declspec(dllexport) int fnTestString(const char* szTest)<br />
{<br />
	return 42;<br />
}

GeneralRe: Unmanaged DLLs Pin
Luc Pattyn15-Jan-08 3:06
sitebuilderLuc Pattyn15-Jan-08 3:06 
GeneralRe: Unmanaged DLLs Pin
Dave Kreskowiak15-Jan-08 3:58
mveDave Kreskowiak15-Jan-08 3:58 
GeneralRe: Unmanaged DLLs Pin
Luc Pattyn15-Jan-08 4:09
sitebuilderLuc Pattyn15-Jan-08 4:09 
GeneralRe: Unmanaged DLLs Pin
Charles Keepax15-Jan-08 5:39
Charles Keepax15-Jan-08 5:39 
Generalword programming Pin
ps_prakash0215-Jan-08 1:56
ps_prakash0215-Jan-08 1:56 
GeneralRe: word programming Pin
Dave Kreskowiak15-Jan-08 4:34
mveDave Kreskowiak15-Jan-08 4:34 
GeneralRe: word programming Pin
ps_prakash0216-Jan-08 2:17
ps_prakash0216-Jan-08 2:17 
GeneralEmail and SQL 2000 Pin
Illegal Operation15-Jan-08 1:46
Illegal Operation15-Jan-08 1:46 
GeneralRe: Email and SQL 2000 Pin
Dave Kreskowiak15-Jan-08 4:10
mveDave Kreskowiak15-Jan-08 4:10 
GeneralSalam, TabControl With an x built in Closing button Pin
Mohammed Amine15-Jan-08 0:04
Mohammed Amine15-Jan-08 0:04 
GeneralRe: Salam, TabControl With an x built in Closing button Pin
Dave Kreskowiak15-Jan-08 2:00
mveDave Kreskowiak15-Jan-08 2:00 
GeneralDraco.Ignition... Pin
Daytona_67514-Jan-08 23:27
Daytona_67514-Jan-08 23:27 
GeneralConvert .NET 2.0 TO 3.0 CODE Pin
plural14-Jan-08 22:22
plural14-Jan-08 22:22 
GeneralRe: Convert .NET 2.0 TO 3.0 CODE Pin
pmarfleet15-Jan-08 1:55
pmarfleet15-Jan-08 1:55 
GeneralRe: Convert .NET 2.0 TO 3.0 CODE Pin
Dave Kreskowiak15-Jan-08 1:58
mveDave Kreskowiak15-Jan-08 1:58 
GeneralUpdating the Correct record in the Update Statement of the Adapter(Dave) Pin
Vimalsoft(Pty) Ltd14-Jan-08 22:08
professionalVimalsoft(Pty) Ltd14-Jan-08 22:08 
GeneralRe: Updating the Correct record in the Update Statement of the Adapter(Dave) [modified] Pin
Vimalsoft(Pty) Ltd14-Jan-08 23:01
professionalVimalsoft(Pty) Ltd14-Jan-08 23:01 

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.