473,486 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Help needed in interoping a structure in VC++ CLR

1 New Member
Hi,
i am new to .NET framework so not that knowledgable about managed and unmanaged codes.

The problem i am facing is i need to call a function say fun_test(struct test * A) which is present in an unmanaged dll, from my CLR class library.

The structure 'test' is present in unmanaged C file as

struct test{
int x;
char info[5];
};

The fuction fun_test just populates some value in to the reference structure.


I declared the structure and marshalled the textinfo as shown

[StructLayout(LayoutKind::Sequential)]
ref struct test{
int x;

[System::Runtime::InteropServices::MarshalAsAttribu te(System::Runtime::InteropServices::UnmanagedType ::ByValTStr,SizeConst=5)] System::String^ textinfo;
};
//I imported the fuction as below

[DllImport("test.dll",EntryPoint="test_struct_fun")]
static int fun_test( test^ struct_instance);

I get no compilation or runtime error but the structure whose reference i passed is not getting updated at all.

This is how i call fun_test from my managed code.
int classA::wrapper(){


classA::test_struct^ struct_instance1 = gcnew test_struct();

fun_test((test_struct^)struct_instance1);


if ( struct_instance1->x == 2){
return 3;
}

return 0;
}

NOTE: I am able to call this function succesfully with the structure getting populated if i removed the char[5] member from the structure.
I suspect it has to do something with the marshalling of char to string^ or its initialization.

I was able to call this function succesfully with C# and VB where char Info[5] is marshalled as String.

Thanks in advance
Rocky
May 30 '07 #1
0 947

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

Similar topics

4
2460
by: Zoran Stipanicev | last post by:
Hi! I have a code that looks some thing like this void function() { struct st1 { template<...> struct st2 {
1
3999
by: Robert Rota | last post by:
Hello, Please help me with the following struct development: I need three levels of a data structure simulating a 3 level pagetable. I need a structure which has a pointer to an array of...
13
2900
by: Brett Baisley | last post by:
At school, we do all of our coding in emacs, but I am trying to get the example apps working at home using Visual C++.net. In the example, there are 4 .cpp files (canvas.cpp, main.cpp,...
5
1995
by: Udi | last post by:
Hi, How do I work with a C++ class that is given through a dll? can someone please give me a short C# example of how to work with the following code? Thanks! class MyClass { private:
5
2276
by: SStory | last post by:
Hi all, I really needed to get the icons associated with each file that I want to show in a listview. I used the follow modified code sniplets found on the internet. I have left in...
9
8190
by: Danny Mavromatis | last post by:
I have a chunk of VC.NET code (below) that I need to convert to VB.NET syntax. Could someone help me get started? I'm new to structures and unions and I don't understand how to nest then in...
5
1308
by: s33k3r | last post by:
hi all I've been assigned the task of designing a distributed application from scratch. I have no legacy applications to integrate or support. But I'm faced with the question : Is visual c++.net...
2
5141
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. ...
2
1969
by: parvtb | last post by:
Thanks for your patience to read the entire post to understand my confusion I have the user-defined class "tools": class tools{ public: tools( ......) {} friend bool operator<...
0
6964
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
7123
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,...
1
6842
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
5430
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4559
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...
0
3070
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1378
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 ...
1
598
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
262
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...

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.