Calling an unmanaged DLL from Visual Studio 2003 Visual Basic

G

Guest

Hall
I want to call an unmanaged dll, written in eMbedded Visual C++ 4.
from Visual Studio 2003 Visual Basic, for an application for Pocket PC 2003
I have tried with "Public Declare Function MSR3000_Open Lib "msr8800.dll" (..." and with the DllImport-statement
but the "MissingMethodException" occurs every time
I dont know how to set/declare the parameters

The function-declaration in the dll

typedef DWORD RET_STATUS
MSR8800_API RET_STATUS Msr3000_Open(TCHAR *ptrSerialPort, TCHAR *ptrDllVersion
TCHAR *ptrFirmwareVersion, void *pPortHandle


I have a program written in eMbedded Visual C++ 4.0 and the call from that program looks like this

DWORD rs
TCHAR szPort[] = _T("COM1:"); // Serial Por
TCHAR szDll[40]; // to receive version inf
TCHAR szFirm[40]; // to receive firmware versio
TCHAR szDummy[20]; // for unused parameter
rs = Msr3000_Open(szPort,szDll, szFirm, szDummy)

Regards Ã…ke
 
G

Guest

Hi Ã…ke

Working with unmanaged dll calls is sometimes quite tricky. There are
a few simple steps that you should verify

1. Does the executable locate the correct dl
2. Check the exported symbols with dumpbin /export

I'm not completely shure but I think that missing method exceptions only
occur when the runtime fails to locate a managed method, and that the
exception that you probably should encounter if there is a missmatch
between managed/unmanaged code is EntrypointNotFoundException
(but I can't verify this at this point

Best Regards, Daniel Peterson
 
G

Guest

The dumpbin /exports give me
10 9 0000100F ?Msr3000_Open@@YAKPAG00PAX@

It dont say me a thing

The following call give me "A managed InvalidCastException"

<DllImport("msr8800.dll", CallingConvention:=CallingConvention.Winapi,
CharSet:=CharSet.Unicode, EntryPoint:="Msr3000_Open")>
Public Shared Function
Msr3000_OpenW(ByVal ptrSerialPort As Byte, ByVal ptrDllVersion As Byte,
ByVal ptrFirmwareVersion As Byte, ByVal pPortHandle As Byte) As UInt3
End Functio

Public svar_open As UInt3
Public svar_close As Int3
Public szPort As Strin
Public szDll As Strin
Public szFirm As Strin
Public szDummy As Strin

Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Clic
szPort = "COM1:
svar = Form1.Msr3000_OpenW(szPort, szDll, szFirm, szDummy
svar_open = Form1.Msr3000_OpenW(szPort, szDll, szFirm, szDummy

Another question: How do you write the right path on Pocket PC 2003 for msr8800.dll
 
A

Alex Yakhnin [MVP]

http://msdn.microsoft.com/mobility/prodtechinfo/devtools/netcf/FAQ/default.a
spx#6.1

--
--
Alex Yakhnin .NET CF MVP
www.intelliprog.com | www.opennetcf.org

AkeK said:
The dumpbin /exports give me:
10 9 0000100F ?Msr3000_Open@@YAKPAG00PAX@Z

It dont say me a thing!

The following call give me "A managed InvalidCastException":

<DllImport("msr8800.dll", CallingConvention:=CallingConvention.Winapi, _
CharSet:=CharSet.Unicode, EntryPoint:="Msr3000_Open")> _
Public Shared Function _
Msr3000_OpenW(ByVal ptrSerialPort As Byte, ByVal ptrDllVersion As Byte, _
ByVal ptrFirmwareVersion As Byte, ByVal pPortHandle As Byte) As UInt32
End Function

Public svar_open As UInt32
Public svar_close As Int32
Public szPort As String
Public szDll As String
Public szFirm As String
Public szDummy As String

Private Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
 
C

Chris Tacke, eMVP

The name is mangled, and your declaration cannot find it.

http://msdn.microsoft.com/mobility/.../en-us/dnnetcomp/html/netcfdumpbinpinvoke.asp

--
Chris Tacke, eMVP
Co-Founder and Advisory Board Member
www.OpenNETCF.org
---
Windows CE Product Manager
Applied Data Systems
www.applieddata.net


AkeK said:
The dumpbin /exports give me:
10 9 0000100F ?Msr3000_Open@@YAKPAG00PAX@Z

It dont say me a thing!

The following call give me "A managed InvalidCastException":

<DllImport("msr8800.dll", CallingConvention:=CallingConvention.Winapi, _
CharSet:=CharSet.Unicode, EntryPoint:="Msr3000_Open")> _
Public Shared Function _
Msr3000_OpenW(ByVal ptrSerialPort As Byte, ByVal ptrDllVersion As Byte, _
ByVal ptrFirmwareVersion As Byte, ByVal pPortHandle As Byte) As UInt32
End Function

Public svar_open As UInt32
Public svar_close As Int32
Public szPort As String
Public szDll As String
Public szFirm As String
Public szDummy As String

Private Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
 
G

Guest

Hallo and thanks for all help
I havent solved it yet, but I going to try on wednesda
Best regards Ã…ke
 
A

Alex Feinman [MVP]

http://www.alexfeinman.com/download.asp?doc=MsrReader.zip
But you will be better off obtaining Symbol Mobility .NET SDK that contains
predefined classes for MSR 3000

AkeK said:
Hallo
I want to call an unmanaged dll, written in eMbedded Visual C++ 4.0
from Visual Studio 2003 Visual Basic, for an application for Pocket PC 2003.
I have tried with "Public Declare Function MSR3000_Open Lib "msr8800.dll"
(..." and with the DllImport-statement,
but the "MissingMethodException" occurs every time.
I dont know how to set/declare the parameters.

The function-declaration in the dll:

typedef DWORD RET_STATUS;
MSR8800_API RET_STATUS Msr3000_Open(TCHAR *ptrSerialPort, TCHAR *ptrDllVersion,
TCHAR *ptrFirmwareVersion, void *pPortHandle)
{

I have a program written in eMbedded Visual C++ 4.0 and the call from that program looks like this:

DWORD rs;
TCHAR szPort[] = _T("COM1:"); // Serial Port
TCHAR szDll[40]; // to receive version info
TCHAR szFirm[40]; // to receive firmware version
TCHAR szDummy[20]; // for unused parameters
rs = Msr3000_Open(szPort,szDll, szFirm, szDummy);

Regards Åke
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top