473,698 Members | 2,411 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using P/Invoke to call a pointer to a pointer

I am currently calling a 3rd party external library using P/Invoke.
The library gives me a handful of functions that I need to call. I
have been successful at calling many of them, but I am some trouble
calling a certain function that requires a pointer to a pointer. Here
is the relevant header information:

typedef struct _ITEM_INFO
{
int itemID;
int itemValue;
} ITEM_INFO;

typedef struct _ITEMS
{
int count; /* number of items */
ITEM_INFO * itemList; /* list of iteminfo */
} ITEMS;

RESULT_CODE WINAPI GetItemList(ITE MS ** itemList);

I need a way to call the GetItemList. In the end, I need the list of
itemIDs and their associated values. I found an article on a technique
for calling a pointer to a pointer to a struct at
http://www.vsj.co.uk/articles/display.asp?id=501. That technique used
the Marshal.AllocHG lobal and Marshal.Structu reToPtr methods, but the
Marshal.AllocHG lobal requires a size parameter for the ITEMS structure.
However, this structure does not have a constant size due to the list
inside of it. Does anyone know how I might be able to call this
function from C#?

Thanks for your help.

Jim

Oct 9 '06 #1
1 1478
>I need a way to call the GetItemList. In the end, I need the list of
>itemIDs and their associated values. I found an article on a technique
for calling a pointer to a pointer to a struct at
http://www.vsj.co.uk/articles/display.asp?id=501. That technique used
the Marshal.AllocHG lobal and Marshal.Structu reToPtr methods, but the
Marshal.AllocH Global requires a size parameter for the ITEMS structure.
Are you sure you have to allocate the memory? From the signature it
looks like the caller allocates and returns a pointer through the only
parameter. In that case, just type it as out IntPtr on the C# side.

However, this structure does not have a constant size due to the list
inside of it.
The struct itself still has a constant size (sizeof(int) +
sizeof(ITEM_INF O*)).
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Oct 9 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
6593
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on where the job is running, the job runs sucessfully, PDF files got generated, everything is good. If I scheduled the job to run at the time that I am not logged into the server, Access is not able to print to the printer. The error is pretty...
16
2498
by: Duncan Mole | last post by:
Hi, This is probably an easy one but it iy first bit of p/invoke. I am trying to use the following C struct in a call: typedef struct { BYTE SRB_Cmd; BYTE SRB_Status, BYTE SRB_HaId;
0
1478
by: brckcc | last post by:
I have a function in C which takes a pointer to a pointer to a structure. It then returns a linked list. How do I call, via P/Invoke, from C# to C. struct LinkedList { char *value; struct LinkedList *next; }
1
2332
by: Marek | last post by:
Hi I need to call a native function in a C++ dll from my C#. The C++ function declaration is shown below. The C# code that I have been trying to perform the call is also shown below. All it is trying to do is to pass in two integers, add them together and return the result in the third parameter (byref/as a pointer). The problem is how do I specify the third parameter to be a pointer to type int?
17
2433
by: Johs32 | last post by:
When I make a pointer I have read that if I would like to use it in another function, I need to malloc it first else it will disapear after the function returns. In this code I do not use malloc, but it still works and the function print_me() prints the correct text. Why does it work eventhough I do not use malloc? johs
1
2024
by: colinjack | last post by:
Hi All, I've been using the original (non-event based) asynchronous design pattern using delegates. It works fine but performance wise I know using the ThreadPool is supposed to be far better, so I wondered if anyone had any examples of the best way to do this. I've obviously had a look myself but haven't gotten very far and although I've implemented a version myself I'm not sure its the best that can be done.
89
6041
by: Cuthbert | last post by:
After compiling the source code with gcc v.4.1.1, I got a warning message: "/tmp/ccixzSIL.o: In function 'main';ex.c: (.text+0x9a): warning: the 'gets' function is dangerous and should not be used." Could anybody tell me why gets() function is dangerous?? Thank you very much. Cuthbert
10
2146
by: Neville Lang | last post by:
Hi all, Here is a problem I first struck a while back in the Compact Framework. I am now using the full Framework (v2.0) and wanted to know whether there is anyway around this issue without building separate shim code in another DLL. Here is the layout of the external C DLL function: int thisFunction( double a, int b, double* c)
9
2915
by: Money | last post by:
If I allocate memory like this int *ptr = new int; Can I apply delete ptr; instead of delete ptr; since I am only allocating memory for 1 integer.
0
8685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9171
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9032
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8905
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8880
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5869
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4373
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.