PC Review


Reply
Thread Tools Rate Thread

Calling win32 C++ dll from C#

 
 
=?Utf-8?B?RnJhbmNvaXNWaWxqb2Vu?=
Guest
Posts: n/a
 
      5th Jan 2007
Hi there,

I need to make a call into an unmanaged DLL from a C# application, and I am
getting a SafeArrayTypeMismatchException which basically means that either
what I am sending to the DLL is incorrect, or what I am getting out is not
what the C# code expects.

My question is this: How do I know which array is the troublesome one?
Within the call there are numerous arrays all contained within different
structs.

Regards,

FV
 
Reply With Quote
 
 
 
 
DeveloperX
Guest
Posts: n/a
 
      5th Jan 2007
Can you post the function prototype? I'd guess there's some sort of
pointer to a buffer and a length parameter as a minimum?


FrancoisViljoen wrote:
> Hi there,
>
> I need to make a call into an unmanaged DLL from a C# application, and I am
> getting a SafeArrayTypeMismatchException which basically means that either
> what I am sending to the DLL is incorrect, or what I am getting out is not
> what the C# code expects.
>
> My question is this: How do I know which array is the troublesome one?
> Within the call there are numerous arrays all contained within different
> structs.
>
> Regards,
>
> FV


 
Reply With Quote
 
Jianwei Sun
Guest
Posts: n/a
 
      5th Jan 2007
FrancoisViljoen wrote:
> [DllImport("filename.dll", EntryPointentrypointname")]
> private static extern int DoStuff(ref Series pData, ref StdStat
> pStdstat, ref Settings pSettings, ref EXSM pExSm, ref BOXJ pBj, ref SMA pSma,
> ref Dscr pDsc, ref Croston pCroston);
>
> where each of the parameters is a struct of which some contain arrays.
>
>
>
>
> "DeveloperX" wrote:
>
>> Can you post the function prototype? I'd guess there's some sort of
>> pointer to a buffer and a length parameter as a minimum?
>>
>>
>> FrancoisViljoen wrote:
>>> Hi there,
>>>
>>> I need to make a call into an unmanaged DLL from a C# application, and I am
>>> getting a SafeArrayTypeMismatchException which basically means that either
>>> what I am sending to the DLL is incorrect, or what I am getting out is not
>>> what the C# code expects.
>>>
>>> My question is this: How do I know which array is the troublesome one?
>>> Within the call there are numerous arrays all contained within different
>>> structs.
>>>
>>> Regards,
>>>
>>> FV

>>


It's best that you can also post your code to show us how you call it.
 
Reply With Quote
 
Ben Voigt
Guest
Posts: n/a
 
      5th Jan 2007

"FrancoisViljoen" <francoisv at dev dot barloworldoptimus dot com> wrote in
message news:C8069DF4-07A3-4215-9343-(E-Mail Removed)...
> [DllImport("filename.dll", EntryPointentrypointname")]
> private static extern int DoStuff(ref Series pData, ref StdStat
> pStdstat, ref Settings pSettings, ref EXSM pExSm, ref BOXJ pBj, ref SMA
> pSma,
> ref Dscr pDsc, ref Croston pCroston);
>
> where each of the parameters is a struct of which some contain arrays.


When you define those structs in C#, you probably need to be using the
"fixed" keyword, otherwise C# assumes they are SAFEARRAYs.

>
>
>
>
> "DeveloperX" wrote:
>
>> Can you post the function prototype? I'd guess there's some sort of
>> pointer to a buffer and a length parameter as a minimum?
>>
>>
>> FrancoisViljoen wrote:
>> > Hi there,
>> >
>> > I need to make a call into an unmanaged DLL from a C# application, and
>> > I am
>> > getting a SafeArrayTypeMismatchException which basically means that
>> > either
>> > what I am sending to the DLL is incorrect, or what I am getting out is
>> > not
>> > what the C# code expects.
>> >
>> > My question is this: How do I know which array is the troublesome one?
>> > Within the call there are numerous arrays all contained within
>> > different
>> > structs.
>> >
>> > Regards,
>> >
>> > FV

>>
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
calling unmanaged code in Win32 API Tony Johansson Microsoft C# .NET 2 29th Apr 2010 03:06 PM
Problem calling Win32 API AddMonitor() Jostein Leira Microsoft Dot NET 2 21st Feb 2008 08:31 AM
calling win32 api from C++ forms project Steve Richter Microsoft VC .NET 2 5th Mar 2007 05:59 AM
Calling a Win32 Dll nbotw Microsoft Dot NET 5 21st Oct 2003 03:39 PM
Calling Win32 dlls Otis Mukinfus Microsoft C# .NET 1 15th Sep 2003 01:40 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:43 PM.