PC Review Forums Newsgroups Microsoft DotNet Microsoft Dot NET Compact Framework Calling an unmanaged DLL from Visual Studio 2003 Visual Basic

Reply

Calling an unmanaged DLL from Visual Studio 2003 Visual Basic

 
Thread Tools Rate Thread
Old 15-03-2004, 08:41 AM   #1
=?Utf-8?B?QWtlSw==?=
Guest
 
Posts: n/a
Default Calling an unmanaged DLL from Visual Studio 2003 Visual Basic


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
  Reply With Quote
Old 15-03-2004, 11:36 AM   #2
=?Utf-8?B?RGFuaWVsIFBldGVyc3Nvbg==?=
Guest
 
Posts: n/a
Default RE: Calling an unmanaged DLL from Visual Studio 2003 Visual Basic

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
  Reply With Quote
Old 15-03-2004, 01:06 PM   #3
=?Utf-8?B?QWtlSw==?=
Guest
 
Posts: n/a
Default No success


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

  Reply With Quote
Old 15-03-2004, 01:25 PM   #4
Alex Yakhnin [MVP]
Guest
 
Posts: n/a
Default Re: No success

http://msdn.microsoft.com/mobility/...f/FAQ/default.a
spx#6.1

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

"AkeK" <anonymous@discussions.microsoft.com> wrote in message
news:E9BE8C4A-21BC-4A31-8EC1-D7E3DFF78187@microsoft.com...
>
> 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
> 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 ?
>



  Reply With Quote
Old 15-03-2004, 02:42 PM   #5
Chris Tacke, eMVP
Guest
 
Posts: n/a
Default Re: No success

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

http://msdn.microsoft.com/mobility/...pbinpinvoke.asp

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


"AkeK" <anonymous@discussions.microsoft.com> wrote in message
news:E9BE8C4A-21BC-4A31-8EC1-D7E3DFF78187@microsoft.com...
>
> 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
> 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 ?
>



  Reply With Quote
Old 15-03-2004, 03:26 PM   #6
=?Utf-8?B?QWtlSw==?=
Guest
 
Posts: n/a
Default From AkeK

Hallo and thanks for all help
I havent solved it yet, but I going to try on wednesda
Best regards Ã…ke
  Reply With Quote
Old 15-03-2004, 05:06 PM   #7
Alex Feinman [MVP]
Guest
 
Posts: n/a
Default Re: Calling an unmanaged DLL from Visual Studio 2003 Visual Basic

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

"AkeK" <anonymous@discussions.microsoft.com> wrote in message
news:CA1CAA05-5495-4B89-9C71-85CD34E7BDB5@microsoft.com...
> 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



  Reply With Quote
Old 17-03-2004, 08:56 AM   #8
=?Utf-8?B?QWtlSw==?=
Guest
 
Posts: n/a
Default Thanks

Thanks for the answer, I think this is what I need
Regards Ã…ke
  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off