I have a working VC++2010 app that needs to be ported to VB2010. But I seem to be having difficulty passing a pointer to an array of structures to a DLL. I cannot modify the DLL.
working VC++ reference... - // pasted from header
-
ABDNAPI int DNET_EnumPorts
-
(
-
PORT_ATTRIBUTES * pPortsArray,
-
int * nNumPorts
-
);
-
-
// pasted from code
-
-
PORT_ATTRIBUTES pPortsArray[50];
-
-
status = DNET_EnumPorts(pPortsArray, &nNumPorts);
resultant structure... pPortsArray = 0x0012fe78 {port_num='Ì' mac_id='Ì' baud_rate='Ì' ...}
[0] = {port_num='Ì' mac_id='Ì' baud_rate='Ì' ...}
port_num = 204 'Ì'
mac_id = 204 'Ì'
baud_rate = 204 'Ì' I'm not sure if the problem is with the VB definition or the VB call...
non-working VB version... - <DllImport("pcidios.dll", EntryPoint:="DNET_EnumPorts", SetLastError:=True, _
-
CharSet:=CharSet.Unicode, ExactSpelling:=True, _
-
CallingConvention:=CallingConvention.StdCall)> _
-
Private Shared Function DNET_EnumPorts( _
-
ByVal pPortsArray As Long, _
-
ByRef nNumPorts As Integer) As Integer
-
End Function
-
'pPortsArray as IntPtr results in unbalanced stack
-
-
Dim PortsArray(50) As PORT_ATTRIBUTES
-
-
'Marshal, first method
-
Dim pPortsArray As IntPtr '= Marshal.AllocHGlobal(Marshal.SizeOf(PortsArray))
-
pPortsArray = Marshal.AllocHGlobal(Marshal.SizeOf(GetType(PORT_ATTRIBUTES)) * 50)
-
Dim lPortsArray As Long = pPortsArray.ToInt64
-
status = DNET_EnumPorts(lPortsArray, nNumPorts)
-
'AccessViolationException was unhandled
-
'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
-
-
'GCHandle, second method
-
Dim pGCHPortsArray As IntPtr = GCHandle.Alloc(PortsArray, GCHandleType.Normal)
-
Dim lGCHPortsArray As Long = pGCHPortsArray.ToInt64
-
status = DNET_EnumPorts(lGCHPortsArray, nNumPorts)
-
'AccessViolationException was unhandled
-
'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
- 'third method
-
<DllImport("pcidios.dll", EntryPoint:="DNET_EnumPorts", SetLastError:=True, _
-
CharSet:=CharSet.Unicode, ExactSpelling:=True, _
-
CallingConvention:=CallingConvention.StdCall)> _
-
Private Shared Function DNET_EnumPorts( _
-
ByRef PortsArray As Object, _
-
ByRef nNumPorts As Integer) As Integer
-
End Function
-
-
Dim PortsArray(50) As PORT_ATTRIBUTES
-
-
status = DNET_EnumPorts(PortsArray, nNumPorts)
-
'ArgumentException was caught
-
'The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
Thanks for your ideas.
Bob
0 1566 Sign in to post your reply or Sign up for a free account.
Similar topics
by: dati_remo |
last post by:
Hi, is it possible to find the dimension of an array using a pointer?
main()
{
int a;
f(a);
return;
}
|
by: caleb.vandyke |
last post by:
I am working with some code that is doing some pointer to structure
casts and I can't figure out how the cast is being done. Here is
basically the code.
#include <stdio.h>
#include <stdlib.h>
...
|
by: ravi |
last post by:
Hi,
i am a c++ programmer,
now i want to learn programming in c also.
so can anybody explain me the difference b/w call by reference and
call by
pointer (with example if possible).
|
by: meisterbartsch |
last post by:
Hi NG,
I want to load a structure from a matlab file (*.mat) into vc++. In
the best case I would have a matching structure in vc++ to acces the
data of the loaded matlab structure.
...
|
by: Phoenix |
last post by:
Hi Friends ,
Could anyone please help me to resolve the following issue :
I pass an array of structures to a dll written in VC++ 6.0 whih fills
it with data . The following works well for VB...
|
by: aruna.mysore |
last post by:
Hi all,
I have a specific problem passing a function pointer array as a
parameter to a function. I am trying to use a function which takes a
function pointer array as an argument. I am too sure...
|
by: Nasif |
last post by:
Dear All
I am using a C++ DLL which has two function , one returns a void
pointer, other returns a pointer to structure .But I doing my project
on C#.
Which data types in C# should I use to...
|
by: goo.one1 |
last post by:
Hi All,
I'm looking for info on how to port VC++ 6 code/projects to VC++ 9
(2008).
I noticed that there is a converter built-in for Visual *BASIC* to
convert from VS6 to 9...
I have found...
|
by: Immortal Nephi |
last post by:
I would like to design an object using class. How can this class
contain 10 member functions. Put 10 member functions into member
function pointer array.
One member function uses switch to call...
|
by: dissectcode |
last post by:
Hello - Please tell me what this is...It looks like an array/structure/prototype/pointer...
STATIC void *_aname = { { &d0, &d1 } , { &d10, &d11 } } ;
i've never seen this before please...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
| | |