473,508 Members | 2,454 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calling win32 C++ dll from C#

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
Jan 5 '07 #1
3 2897
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
Jan 5 '07 #2
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.
Jan 5 '07 #3

"FrancoisViljoen" <francoisv at dev dot barloworldoptimus dot comwrote in
message news:C8**********************************@microsof t.com...
[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


Jan 5 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2334
by: Luca Arena | last post by:
Hi, I would like to know if it is possible to call the php parser from a Win32 program (e.g. a VB or C++ program), WITHOUT calling the commandline php.exe utility. I mean, is there any "php_parse"...
8
1456
by: Patrick Useldinger | last post by:
Hi all, I am looking for beta-testers for fdups. fdups is a program to detect duplicate files on locally mounted filesystems. Files are considered equal if their content is identical,...
3
8715
by: gerald.maher | last post by:
I am trying to run an Corba example using Python and i get the follwing error: import _omnipy ImportError: No module named _omnipy Where can i find this Module ?
5
2496
by: nbotw | last post by:
Hi, I need a function call in my xml web service. I have an old win32 dll and i have created a class to have my declaration in. Imports System.Runtime.InteropServices Public Class Win32
0
303
by: Dale McGorman | last post by:
The following is some code that I am trying to bring over from VB 6.0, that I have working there. I am trying to get to where I can talk to a USB device. I am stuck on how to correctly pass params...
15
11727
by: Bryan | last post by:
I have a multi-threaded C# console application that uses WMI (System.Management namespace) to make RPC calls to several servers (600+ ) and returns ScheduledJobs. The section of my code that...
1
1564
by: Wilfried Mestdagh | last post by:
Hi, I have a few related questios: 1. if I pass a string to win32 api (or other dll not written in .net), is it possible GC cleans up while function is still busy ? eg: public class Win32...
11
1927
by: j23 | last post by:
I have library (static) testlib.cpp: #include <stdarg.h> void xxx(...) { char buf; va_list args; va_start(args, buf); va_end(args); }
0
1166
by: Scott Gunn | last post by:
Hello I'm trying to scroll a region of graphics, the best way I can see is to use the ScrollWindowEx API because it is designed for doing this However it doesn't work correctly, Why? Here...
2
2808
by: Daniel Lidström | last post by:
I'm using a library called fyba. This library reads and writes files in a format called sosi. fyba uses the following code to determine if the calling process has own methods to handle errors,...
0
7229
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7129
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
7398
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
5637
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
4716
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
3208
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...
0
3194
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1566
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 ...
0
428
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.