eVC .dll in vb.net on PocketPC 2003

G

Guest

I am having trouble accessing a .dll created in eVC through vb.net. The function for the .dll looks like the following in eVC

__declspec(dllexport
int WINAPI foo3 (int inval

return inval+10


Inside of my VB appliation, I have the following

Imports System.Runtime.InteropService

<DllImport("CProcess.DLL")>
Public Function foo3(ByVal foo As Integer) As Intege
End Functio

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Clic
Dim retval As Intege
Dim inVal As Intege

retval = foo3(inVal
inVal = 1
retval = foo3(inVal
retval = foo4(inVal
End Su
End Clas

The first call to foo3 returns correctly (inVal = 0, retVal = 10). However, on the second call to foo3, the PDA reports "A native exception occurred. ExceptionCode: 0x80000002 ...". The PDA seems to be complaining about data not being aligned properly. Can anyone help me figure this one out? I've got plenty of VC++ experience, but am new to VB and the PDA world. Thanks.
 
C

Chris Tacke, eMVP

You're certain that's all the code in the C++ method? It sure sounds like
it's stepping on memory somewhere.

-Chris


stephan said:
I am having trouble accessing a .dll created in eVC through vb.net. The
function for the .dll looks like the following in eVC:
__declspec(dllexport)
int WINAPI foo3 (int inval)
{
return inval+10;
}


Inside of my VB appliation, I have the following:

Imports System.Runtime.InteropServices

<DllImport("CProcess.DLL")> _
Public Function foo3(ByVal foo As Integer) As Integer
End Function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim retval As Integer
Dim inVal As Integer

retval = foo3(inVal)
inVal = 10
retval = foo3(inVal)
retval = foo4(inVal)
End Sub
End Class

The first call to foo3 returns correctly (inVal = 0, retVal = 10).
However, on the second call to foo3, the PDA reports "A native exception
occurred. ExceptionCode: 0x80000002 ...". The PDA seems to be complaining
about data not being aligned properly. Can anyone help me figure this one
out? I've got plenty of VC++ experience, but am new to VB and the PDA
world. Thanks.
 
C

Chris Tacke, eMVP

I don't see any problem with your code. The DLL is built for the right
processor, right?


--
Chris Tacke, eMVP
Co-Founder and Advisory Board Member
www.OpenNETCF.org
---
---
Principal Partner
OpenNETCF Consulting
www.OpenNETCF.com



stephan said:
Yes. That is all the code in my method. I've now gotten it to work by
adding Imports System to my VB app, and changing the foo3 function
declaration to
<DllImport("CProcess.dll", CharSet:=CharSet.Unicode, EntryPoint:="foo3")> _
Public Shared Function foo3(ByVal foo As Integer) As Integer
End Function

I have no idea why this has made a difference, but it has.

However, I am now having trouble passing data by reference. I now have a function foo4

__declspec(dllexport)
void WINAPI foo4 (long *inval)
{
*inval = 32;
}

With corresponding VB code

<DllImport("CProcess.DLL", CharSet:=CharSet.Unicode, EntryPoint:="foo4")> _
Public Sub foo4(ByRef foo As Long)
End Sub

And once again, when I call the function foo4, I get an exception "A
native exception occurred. ExceptionCode: 0xc0000005 ..."
All of the example code I've seen on the web does it this way, and I
cannot figure out why this isn't working.
 

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