Hi we have a 3rd party in process com dll, which was written In C++ and our
client is in c#.
All is working fine apart from we get a callback from the DLL which contains
an array of structures.
The callback signature looks like this,
With the list stored in the radioSubscriber Attributes3List , which is defined
in the type library which was created when we imported the com dll into .net
unsafe private void GroupManager_Ge tRadioSubscribe rsConfirmation( uint
radioSubscriber Attributes3List Size, ref tcsRadioSubscri berAttributes3_ t
radioSubscriber Attributes3List , tcsBoolean_t endOfCollection , short cookie);
trouble is we only get the first structure back, if I use the code below.
tcsRadioSubscri berAttributes3_ t[] DATA = new
tcsRadioSubscri berAttributes3_ t[3];
temp = Marshal.AllocCo TaskMem(IntPtr. Size);
buffer = Marshal.AllocCo TaskMem(IntPtr. Size);
//get the address in buffer
Marshal.Structu reToPtr(radioSu bscriberAttribu tes3List, buffer, true);
temp = buffer;
for(int a=0; a<radioSubscrib erAttributes3Li stSize; a++ )
{
DATA[a] =
(tcsRadioSubscr iberAttributes3 _t)Marshal.PtrT oStructure(temp ,radioSubscribe rAttributes3Lis t.GetType());
temp = (IntPtr)((int)b uffer +
Marshal.SizeOf( radioSubscriber Attributes3List .GetType()));
}
I guess StructureToPtr copies the first item from the list passed to us,
into managed memory, and not the rest.
Any help, as if we don’t get this working we will have to write the client
in Delphi !!!!
Cheers Rich. 7 2037
Rich,
I cannot gurantee this is the right answer, but if I were you, I will
try that.
When calling Marshal.Structu reToPtr, I will increment the buffer value
just as you did when calling PtrToStructure.
Something like
for(int a=0; a<radioSubscrib erAttributes3Li stSize; a++ )
{
IntPtr temp;
temp = IntPtr(buffer+a *size);
Marshal.Structu reToPtr(radioSu bscriberAttribu tes3List, temp, true);
}
HTH
Rich Claxton wrote: Hi we have a 3rd party in process com dll, which was written In C++ and our client is in c#.
All is working fine apart from we get a callback from the DLL which contains an array of structures.
The callback signature looks like this,
With the list stored in the radioSubscriber Attributes3List , which is defined in the type library which was created when we imported the com dll into .net
unsafe private void GroupManager_Ge tRadioSubscribe rsConfirmation( uint radioSubscriber Attributes3List Size, ref tcsRadioSubscri berAttributes3_ t radioSubscriber Attributes3List , tcsBoolean_t endOfCollection , short cookie);
trouble is we only get the first structure back, if I use the code below.
tcsRadioSubscri berAttributes3_ t[] DATA = new tcsRadioSubscri berAttributes3_ t[3]; temp = Marshal.AllocCo TaskMem(IntPtr. Size); buffer = Marshal.AllocCo TaskMem(IntPtr. Size);
//get the address in buffer Marshal.Structu reToPtr(radioSu bscriberAttribu tes3List, buffer, true); temp = buffer;
for(int a=0; a<radioSubscrib erAttributes3Li stSize; a++ ) { DATA[a] = (tcsRadioSubscr iberAttributes3 _t)Marshal.PtrT oStructure(temp ,radioSubscribe rAttributes3Lis t.GetType()); temp = (IntPtr)((int)b uffer + Marshal.SizeOf( radioSubscriber Attributes3List .GetType())); }
I guess StructureToPtr copies the first item from the list passed to us, into managed memory, and not the rest.
Any help, as if we don’t get this working we will have to write the client in Delphi !!!!
Cheers Rich.
Thanks for that, but still no luck.
I think the main problem is that we are getting the adress of the first
struture when we do StructureToPoin ter, but when i look in memmory at this
address i can't see any other struture data that should be on the array after
the first one.
I think the COM c++ is passing us the address of the 1st item in the array
of stuctures and not the array, so when we call StuctureToPoint er we only get
1 stucture.
"Jianwei Sun" wrote: Rich,
I cannot gurantee this is the right answer, but if I were you, I will try that.
When calling Marshal.Structu reToPtr, I will increment the buffer value just as you did when calling PtrToStructure.
Something like
for(int a=0; a<radioSubscrib erAttributes3Li stSize; a++ ) { IntPtr temp; temp = IntPtr(buffer+a *size); Marshal.Structu reToPtr(radioSu bscriberAttribu tes3List, temp, true); }
HTH
Rich Claxton wrote: Hi we have a 3rd party in process com dll, which was written In C++ and our client is in c#.
All is working fine apart from we get a callback from the DLL which contains an array of structures.
The callback signature looks like this,
With the list stored in the radioSubscriber Attributes3List , which is defined in the type library which was created when we imported the com dll into .net
unsafe private void GroupManager_Ge tRadioSubscribe rsConfirmation( uint radioSubscriber Attributes3List Size, ref tcsRadioSubscri berAttributes3_ t radioSubscriber Attributes3List , tcsBoolean_t endOfCollection , short cookie);
trouble is we only get the first structure back, if I use the code below.
tcsRadioSubscri berAttributes3_ t[] DATA = new tcsRadioSubscri berAttributes3_ t[3]; temp = Marshal.AllocCo TaskMem(IntPtr. Size); buffer = Marshal.AllocCo TaskMem(IntPtr. Size);
//get the address in buffer Marshal.Structu reToPtr(radioSu bscriberAttribu tes3List, buffer, true); temp = buffer;
for(int a=0; a<radioSubscrib erAttributes3Li stSize; a++ ) { DATA[a] = (tcsRadioSubscr iberAttributes3 _t)Marshal.PtrT oStructure(temp ,radioSubscribe rAttributes3Lis t.GetType()); temp = (IntPtr)((int)b uffer + Marshal.SizeOf( radioSubscriber Attributes3List .GetType())); }
I guess StructureToPtr copies the first item from the list passed to us, into managed memory, and not the rest.
Any help, as if we don’t get this working we will have to write the client in Delphi !!!!
Cheers Rich.
Rich, With the list stored in the radioSubscriber Attributes3List , which is defined in the type library which was created when we imported the com dll into .net
unsafe private void GroupManager_Ge tRadioSubscribe rsConfirmation( uint radioSubscribe rAttributes3Lis tSize, ref tcsRadioSubscri berAttributes3_ t radioSubscribe rAttributes3Lis t, tcsBoolean_t endOfCollection , short cookie);
trouble is we only get the first structure back, if I use the code below.
And that's all you're going to get as long as the parameter is
declared as "ref tcsRadioSubscri berAttributes3_ t". You'll have to
change that to a real array or an IntPtr by modifying the interop
assembly. How to do that is explained in http://msdn.microsoft.com/library/en...opassembly.asp
Mattias
--
Mattias Sjögren [MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
"Mattias Sjögren" wrote: Rich,
With the list stored in the radioSubscriber Attributes3List , which is defined in the type library which was created when we imported the com dll into .net
unsafe private void GroupManager_Ge tRadioSubscribe rsConfirmation( uint radioSubscribe rAttributes3Lis tSize, ref tcsRadioSubscri berAttributes3_ t radioSubscribe rAttributes3Lis t, tcsBoolean_t endOfCollection , short cookie);
trouble is we only get the first structure back, if I use the code below.
And that's all you're going to get as long as the parameter is declared as "ref tcsRadioSubscri berAttributes3_ t". You'll have to change that to a real array or an IntPtr by modifying the interop assembly. How to do that is explained in
http://msdn.microsoft.com/library/en...opassembly.asp
Mattias
-- Mattias Sjögren [MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com Please reply only to the newsgroup.
Thought as much, thanks for the link.
Cheers Rich.
"Mattias Sjögren" wrote: Rich,
With the list stored in the radioSubscriber Attributes3List , which is defined in the type library which was created when we imported the com dll into .net
unsafe private void GroupManager_Ge tRadioSubscribe rsConfirmation( uint radioSubscribe rAttributes3Lis tSize, ref tcsRadioSubscri berAttributes3_ t radioSubscribe rAttributes3Lis t, tcsBoolean_t endOfCollection , short cookie);
trouble is we only get the first structure back, if I use the code below.
And that's all you're going to get as long as the parameter is declared as "ref tcsRadioSubscri berAttributes3_ t". You'll have to change that to a real array or an IntPtr by modifying the interop assembly. How to do that is explained in
http://msdn.microsoft.com/library/en...opassembly.asp
Mattias
-- Mattias Sjögren [MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com Please reply only to the newsgroup.
Made the changes and it works fine.
another question is this pointing to managed or unmanaged code, i guess
managed as i didnt have to decare the code as unsafe.
Cheers Rich.
"Mattias Sjögren" wrote: Rich,
With the list stored in the radioSubscriber Attributes3List , which is defined in the type library which was created when we imported the com dll into .net
unsafe private void GroupManager_Ge tRadioSubscribe rsConfirmation( uint radioSubscribe rAttributes3Lis tSize, ref tcsRadioSubscri berAttributes3_ t radioSubscribe rAttributes3Lis t, tcsBoolean_t endOfCollection , short cookie);
trouble is we only get the first structure back, if I use the code below.
And that's all you're going to get as long as the parameter is declared as "ref tcsRadioSubscri berAttributes3_ t". You'll have to change that to a real array or an IntPtr by modifying the interop assembly. How to do that is explained in
http://msdn.microsoft.com/library/en...opassembly.asp
Mattias
-- Mattias Sjögren [MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com Please reply only to the newsgroup.
Rich, another question is this pointing to managed or unmanaged code, i guess managed as i didnt have to decare the code as unsafe.
You mean the IntPtr? It's a pointer to the _memory_ (not code) where
the caller allocated the structs. Since the caller is a native C++
library it's most likely not the managed heap, but rather a native
heap or stack.
Mattias
--
Mattias Sjögren [MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Stijn van Dongen |
last post by:
A question about void*. I have a hash library where the hash create
function accepts functions
unsigned (*hash)(const void *a)
int (*cmp) (const void *a, const void *b)
The insert function accepts a void* key argument, and uses the
functions above to store this argument. It returns something (linked to
the key) that the caller can store a value in. The actual key argument
is always of the same pointer type (as seen in the caller,...
|
by: emma middlebrook |
last post by:
Hi
Straight to the point - I don't understand why System.Array derives
from IList (given the methods/properties actually on IList).
When designing an interface you specify a contract. Deriving from an
interface and only implementing some of it means something is wrong:
either the interface specification is wrong e.g. not minimal or the
derivation is wrong e.g. the type can't actually honour this contract.
|
by: MyAlias |
last post by:
Can't solve this CallBack returning structures
Error message:
An unhandled exception of type 'System.NullReferenceException'
occurred in MyTest.exe
Additional information: Object reference not set to an instance of an
object.
Situation skeleton:
Private Declare Function EnumFontFamiliesASCII Lib "gdi32" Alias
|
by: gregory_may |
last post by:
Is there a way in VB.Net to declare a local variable that will manipulate an
array element .... kind of like an item pointer to a global array?
|
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: 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,...
|
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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |