473,406 Members | 2,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

using PInvoke with an array of struct

2
Hi!

I want to call a function from a c++ unmanaged dll but i'm having a hard time in doing it because of an array parameter.

the definition in c++ of the method is:


Expand|Select|Wrap|Line Numbers
  1. int __export __stdcallInsertStruct(int countS,  AInfo info[11])
and

Expand|Select|Wrap|Line Numbers
  1. typedef struct
  2. {
  3. char* a;
  4. char b;
  5. char* c;
  6. }AInfo;
In my c# code i have:

Expand|Select|Wrap|Line Numbers
  1. [StructLayout(LayoutKind.Sequential)]
  2.         public struct AInfo
  3.         {
  4.             public string a;
  5.             public char b;
  6.             public string c;
  7.         }
  8.  
and

Expand|Select|Wrap|Line Numbers
  1. private delegate IntPtr InsertStructDelegate(int countS,  AInfo[] info);
I fill the array before calling this delegate and i
can't manage to get this to work. Always get an error of broken memory.

do i have to use another type instead of AInfo[] in my method definition?
Like IntPtr or byte[]?

Can someone help me with this one?
Apr 26 '10 #1
3 2276
Plater
7,872 Expert 4TB
I don't know specifically, but check the Marshal class for some usefull things.
I think you may have to marshal your object as a special C array. Don't remember how, but I know saw something like that somewhere
Apr 27 '10 #2
puchie
2
I think the problem here is to Marshal the string fields. Does anyone hava an idea on how to do this. I Tried a lot of different approaches without success.

Thanks
Apr 27 '10 #3
Plater
7,872 Expert 4TB
Same deal, somewhere there's a property or something under the marshalling that says "make this a c-style array of char" or lpcstr or something
Apr 27 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Ted Miller | last post by:
Hi folks, I've got an unmanaged routine I'm pinvoking to. It takes a pointer to an array of 3 pointers to bytes, typed as byte**. public static extern void foo(byte **p3pb); unsafe {...
3
by: John Smith | last post by:
I wrote some code in C in a dll which I would like to call from C#. However I'm stuck because of the strongly typed behavior of C# which makes limitations. Here are the prototypes for two...
3
by: Charles Denny | last post by:
I'm trying to call CertFindCertificateInStore to find all certificates in the store that have the Code Signing enhanced key usage. I'm running into problems marshalling the array of OIDs in...
13
by: Kantha | last post by:
Hi all, I have declared an Union as follows typedef union { struct interrupt_bits { unsigned char c_int_hs_fs_status : 1, c_setup_intflag : 1,
3
by: Michael | last post by:
Hi all, I'm having trouble PInvoking a TCHAR within a struct. I'll paste the specific struct's API definition below. I've tried so many numerous variations. The main Win32 error I get is...
7
by: Rymfax | last post by:
I would really appreciate it if someone could help me figure out what I'm doing wrong trying to PInvoke SetupDiEnumDriverInfo. All the other PInvokes i've done up to this point work fine. Whenver...
1
by: eastlands | last post by:
I need to use an unmanaged c++ dll which uses structs that contain callbacks and also functions. I have included the appropriate c++ definitials and my c# translations below. I first defined the...
3
by: not_a_commie | last post by:
The CLR won't garbage collect until it needs to. You should see the memory usage climb for some time before stabilizing. Can you change your declaration to use the 'out' keyword rather than a 'ref'...
5
by: =?Utf-8?B?SmVzc2ljYQ==?= | last post by:
Hello, I have a pInvoke question. This is the C function that is exported from one of the C dll, extern __declspec(dllexport) IM_RET_CODE ST_import (IM_MODE mode, char *filename,...
0
by: emitojleyes | last post by:
Hi everyone! i'm new at this forum as well as programming in .net I have to develop a module that can use and configure a fingerprint detector; its documentation is written in C, as you will see...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...
0
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...
0
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...

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.