I'm at a loss on how to accomplish one item with C# entirely in
managed code -- I'd like to make a call to a Win32 function, one of
its parameters is a structure that contains a pointer to one or more
structures. How do I setup the structure in C# to allow for the
pointer to a structure?
The structure that I'm referring to is MIXERLINECONTRO LS and it's
declaration is the following:
typedef struct {
DWORD cbStruct;
DWORD dwLineID;
union {
DWORD dwControlID;
DWORD dwControlType;
};
DWORD cControls;
DWORD cbmxctrl;
LPMIXERCONTROL pamxctrl;
} MIXERLINECONTRO LS;
For the API that I want to use, it requires that the pamxctrl member
must point to the first MIXERCONTROL structure to be filled.
I can map out most of the C++ struct into the C# equivalent to be able
to do this fully in managed code so it looks like this:
[ StructLayout( LayoutKind.Sequ ential )]
public struct MIXERLINECONTRO LS
{
public uint cbStruct; /* uint is DWORD in C++ */
public uint dwLineID;
union {
public uint dwControlID;
public uint dwControlType;
};
public uint cControls;
public uint cbmxctrl;
LPMIXERCONTROL pamxctrl; //<< **HOW DO I CONVERT THIS INTO C#? >>
};
When I call the Win32API that makes use of the MIXERLINECONTRO LS
struct, I'm not sure how to set up
1) the pointer to the structure that's necessary in the definition of
the struct for C#
2) the allocation of the correct amount of memory for pamxctrl before
I pass it into the call
so that I can get back the list of array items of MIXERCONTROL
3) the accessing of the list of array items of pamxctrl that I get
back from the call.
Could someone point out some suggestions for me? I'd really appreciate
it.
Thanks in advance,
J 3 1812 1) the pointer to the structure that's necessary in the definition of the struct for C#
Make it an IntPtr member.
2) the allocation of the correct amount of memory for pamxctrl before I pass it into the call
With one of the Marshal.Alloc methods.
3) the accessing of the list of array items of pamxctrl that I get back from the call.
Marshal.PtrToSt ructure()
Mattias
--
Mattias Sjögren [MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
J,
I don't have time to test this out but since all ValueTypes have the ability
of using the IntPtr. I would first try replacing the C# struct element
LPMIXERCONTROL with an Int32(int) element. Then create the MIXERCONTROL
struct fill it in. Set the LPMIXERCONTROL Int32 element in MIXERLINECONTRO LS
to the IntPtr.
Then I would test this by writing a unmanaged C++ console app and decalre
the 2 structs. The just call a managed dll method that returns it, so you
can check the return for valid values.
Hope this helps or at least gets you going in the right direction.
--
Glen Jones MCSD
"J" <jg*****@hotmai l.com> wrote in message
news:46******** *************** ***@posting.goo gle.com... I'm at a loss on how to accomplish one item with C# entirely in managed code -- I'd like to make a call to a Win32 function, one of its parameters is a structure that contains a pointer to one or more structures. How do I setup the structure in C# to allow for the pointer to a structure?
The structure that I'm referring to is MIXERLINECONTRO LS and it's declaration is the following: typedef struct { DWORD cbStruct; DWORD dwLineID; union { DWORD dwControlID; DWORD dwControlType; }; DWORD cControls; DWORD cbmxctrl; LPMIXERCONTROL pamxctrl; } MIXERLINECONTRO LS;
For the API that I want to use, it requires that the pamxctrl member must point to the first MIXERCONTROL structure to be filled.
I can map out most of the C++ struct into the C# equivalent to be able to do this fully in managed code so it looks like this:
[ StructLayout( LayoutKind.Sequ ential )] public struct MIXERLINECONTRO LS { public uint cbStruct; /* uint is DWORD in C++ */ public uint dwLineID; union { public uint dwControlID; public uint dwControlType; }; public uint cControls; public uint cbmxctrl;
LPMIXERCONTROL pamxctrl; //<< **HOW DO I CONVERT THIS INTO C#? >> };
When I call the Win32API that makes use of the MIXERLINECONTRO LS struct, I'm not sure how to set up 1) the pointer to the structure that's necessary in the definition of the struct for C# 2) the allocation of the correct amount of memory for pamxctrl before I pass it into the call so that I can get back the list of array items of MIXERCONTROL 3) the accessing of the list of array items of pamxctrl that I get back from the call.
Could someone point out some suggestions for me? I'd really appreciate it.
Thanks in advance, J
Mattias,
I'm following your suggestions. I can allocate enough memory for the
pamxtrl but I am still confused on how to extract each individual
array items that I get back from the call. When PtrToStructure is
used, I'd get the first item as a struct. How can I advance the
pointer in C# to access next set of items in the array? Am I
misunderstandin g how this particular marshalling works?
Thanks for your help,
Jay
Mattias Sjögren <ma************ ********@mvps.o rg> wrote in message news:<eH******* *******@tk2msft ngp13.phx.gbl>. .. 1) the pointer to the structure that's necessary in the definition of the struct for C#
Make it an IntPtr member.
2) the allocation of the correct amount of memory for pamxctrl before I pass it into the call
With one of the Marshal.Alloc methods.
3) the accessing of the list of array items of pamxctrl that I get back from the call.
Marshal.PtrToSt ructure() Mattias This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: timothy.williams |
last post by:
Hi.
I trying to write an extension module to call some C libraries so I can
use them in Python. Several of the library functions pass pointers to
structures as arguments. I was thinking that I could create a class for
each structure, but I'm not sure how to get the data back and forth.
The example the "Extending and Embedding the Python Interpreter" manual
has examples of passing strings and ints using
PyArg_ParseTupleAndKeywords(), but...
|
by: Michael Wu |
last post by:
I wonder if anyone know how to activate a window with a given window
handler. I used to do this with the win32 API
static native boolean SetForegroundWindow(int hwnd);
I wonder if there is native support for that within .NET, instead having to
call WIN32 API.
Regards
|
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...
|
by: ebrahimbandookwala |
last post by:
HI everyone
I am supposed to pass back a pointer to a struct from a function whos
definition cannot be changed
flight_t * get_item(field_t field , void * data)
the problem I encounter is whe I pass back the address of a local var
it gives me garbled output at the calling end ( obv !! )
|
by: vikas |
last post by:
I have following structure in c++.
typedef struct MMF_result_struct
{
int action;
char text;
int cols,rows;
int month,day,year;
} MMF_result;
Now this structure is shared between C++ and C# using memory mapped file. We already have C++ code for handling memory mapped file. I am working on converting code for memory mapped file in C#. Now I have to pass pointer to the above structure. I converted this structure to C# as follows:
| |
by: Peter Demeyer |
last post by:
I have this problem:
'pno' is a pointer to a struct of type PRINTER_NOTIFY_OPTIONS.
This struct is holding another struct called 'not' (of type
PRINTER_NOTIFY_OPTIONS_TYPE) which contains a couple of 'normal' fields
and a pointer (called pFields) to an array of integers.
Now, when I make up everything (probably incorrectly), it compiles ok,
but when I execute this code, I get an error saying that pno is a
nullreference.
|
by: Lokkju |
last post by:
I am pretty much lost here - I am trying to create a managed c++
wrapper for this dll, so that I can use it from c#/vb.net, however, it
does not conform to any standard style of coding I have seen. It is
almost like it is trying to implement it's own COM interfaces...
below is the header, and a link to the dll+code:
Zip file with header, example, and DLL:...
|
by: mohan |
last post by:
Hi All,
How to implement virtual concept in c.
TIA
Mohan
|
by: Peter Hallett |
last post by:
I would like to set up a string array as a class member, or field, and then
populate this array by reading in from a text file, but I cannot find the
appropriate syntax. The getter and setter are very unhappy with the idea and
the compiler refuses to play ball with any of the attempts I have made to
build such a structure. There is no problem when using a single string but a
two dimensional array of strings appears to be a very different...
|
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,...
|
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...
| |
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...
|
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...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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();...
|
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...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
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...
| |