473,320 Members | 1,939 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,320 software developers and data experts.

Dllimport works only in Visual Studio

Hi all,

I have a (for me) strange problem which drives me crazy. I've created
a c# desktop app in visual studio 2005, which uses through dllimports,
methods of an old dll. Afther some tweaking this works fine.

Now my project is finished and i run the 'exe' the dll imports behave
strange, for example i use a unmanaged method that sets a string in my
dll object. This works fine in visual studio but not in the
debugger...

Problem is on unmanaged calls. For example i'm using:
[DllImport("sphapihd.dll", CharSet = CharSet.Ansi)]
static extern void SphSetDataDescr_ArrayINT8([In, Out,
MarshalAs(UnmanagedType.Struct)] ref swDataDescriptor dataDescriptor,
[In, Out, MarshalAs(UnmanagedType.SafeArray)] ref byte[] Values);

Which works under vs.net only not in normal executable. In v.s. this
call sets a certain string value(byte[]) in memory. lateron this
string is used for the rpc call, only the place is empty (not in
debugging mode).

Is there an certain option or something witch i have to set in the
compiler or such thing?

I'm hoping someone has an suggestion...
cheers
Bram Hoefnagel

Sep 27 '07 #1
3 3519
>Problem is on unmanaged calls. For example i'm using:
[DllImport("sphapihd.dll", CharSet = CharSet.Ansi)]
static extern void SphSetDataDescr_ArrayINT8([In, Out,
MarshalAs(UnmanagedType.Struct)] ref swDataDescriptor dataDescriptor,
[In, Out, MarshalAs(UnmanagedType.SafeArray)] ref byte[] Values);

Which works under vs.net only not in normal executable. In v.s. this
call sets a certain string value(byte[]) in memory. lateron this
string is used for the rpc call, only the place is empty (not in
debugging mode).

Is there an certain option or something witch i have to set in the
compiler or such thing?

What's the native code signature for the SphSetDataDescr_ArrayINT8
function?
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Sep 27 '07 #2
On 27 sep, 22:33, Mattias Sjögren <mattias.dont.want.s...@mvps.org>
wrote:
Problem is on unmanaged calls. For example i'm using:
[DllImport("sphapihd.dll", CharSet = CharSet.Ansi)]
static extern void SphSetDataDescr_ArrayINT8([In, Out,
MarshalAs(UnmanagedType.Struct)] ref swDataDescriptor dataDescriptor,
[In, Out, MarshalAs(UnmanagedType.SafeArray)] ref byte[] Values);
Which works under vs.net only not in normal executable. In v.s. this
call sets a certain string value(byte[]) in memory. lateron this
string is used for the rpc call, only the place is empty (not in
debugging mode).
Is there an certain option or something witch i have to set in the
compiler or such thing?

What's the native code signature for the SphSetDataDescr_ArrayINT8
function?

Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.orghttp://www.msjogren.net/dotnet/|http://www.dotnetinterop.com
Please reply only to the newsgroup.

Hi Mattias,
Thanx for your reply.
I'm not sure where I can find this native code signature, I don't have
the source of my dll. I only got the dll itself. If you mean setting
the callingconvention, I've tried all that are available. Funny thing
still is that it works in VS and not in runtime. I'm calling the
function as:

swDataDescriptor wrParam = new swDataDescriptor();
SPHRET ret = new SPHRET();

wrParam.Bytes = Encoding.Default.GetBytes(string.Format("{0}\0",
myString));
SphSetDataDescr_ArrayINT8(ref wrParam, ref wrParam.Bytes);

The string on myString is both in runtime and debugging set to an
array of around 140bytes, and through the SphSetDataDes.. passed
through the dll to my com object. The last part does not work in
runtime, because when i'm getting the string i've set I get some thing
like 4bytes instead of 140.
Cheers,

Sep 28 '07 #3
<br**@plock.nlwrote in message
news:11**********************@o80g2000hse.googlegr oups.com...
On 27 sep, 22:33, Mattias Sjögren <mattias.dont.want.s...@mvps.org>
wrote:
Problem is on unmanaged calls. For example i'm using:
[DllImport("sphapihd.dll", CharSet = CharSet.Ansi)]
static extern void SphSetDataDescr_ArrayINT8([In, Out,
MarshalAs(UnmanagedType.Struct)] ref swDataDescriptor dataDescriptor,
[In, Out, MarshalAs(UnmanagedType.SafeArray)] ref byte[] Values);
Which works under vs.net only not in normal executable. In v.s. this
call sets a certain string value(byte[]) in memory. lateron this
string is used for the rpc call, only the place is empty (not in
debugging mode).
Is there an certain option or something witch i have to set in the
compiler or such thing?

What's the native code signature for the SphSetDataDescr_ArrayINT8
function?

Mattias

--
Mattias Sjögren [C# MVP] mattias @
mvps.orghttp://www.msjogren.net/dotnet/|http://www.dotnetinterop.com
Please reply only to the newsgroup.

Hi Mattias,
Thanx for your reply.
I'm not sure where I can find this native code signature, I don't have
the source of my dll. I only got the dll itself. If you mean setting
the callingconvention, I've tried all that are available. Funny thing
still is that it works in VS and not in runtime. I'm calling the
function as:

swDataDescriptor wrParam = new swDataDescriptor();
SPHRET ret = new SPHRET();

wrParam.Bytes = Encoding.Default.GetBytes(string.Format("{0}\0",
myString));
SphSetDataDescr_ArrayINT8(ref wrParam, ref wrParam.Bytes);

The string on myString is both in runtime and debugging set to an
array of around 140bytes, and through the SphSetDataDes.. passed
through the dll to my com object. The last part does not work in
runtime, because when i'm getting the string i've set I get some thing
like 4bytes instead of 140.
Cheers,
IMO none of the function arguments should NOT be passed byref, that is they
are "In" arguments not "In Out".

Willy.

Sep 28 '07 #4

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

Similar topics

2
by: Paul Duncan | last post by:
diggityduncs (Programmer) Nov 13, 2003 Hello, I'm tring to use a win32/api dll in c# The vendor I received the dll from doesn't know anything about .net I received two files ACGAPI.DLL +
15
by: Jim | last post by:
I am extremely frustrated. I am building c# application for a call center and am using a third party API to access some hardware. When develop and test my class using the windows console the...
3
by: Gawel | last post by:
Hajo, I have two dlls, both of them are compiled with /clr switch. In first dll project I have managed and unmanaged classes. One of the unmanaged I would like to use outside therefore I marked...
1
by: Vagabond Software | last post by:
I am trying to convert a C# .NET wrapper for Microsoft's unmanaged 'cabinet.dll' to Visual Basic .NET and have hit a stumbling block. Here is the C# code that I am trying to convert: private...
1
by: nirbhay | last post by:
Hello All I am experiencing a problem calling one of my un-managed C++ DLL from a Web page This was working fine in Visual Studio 2003 version but gives following error in Visual Studio 2005...
0
by: vidya pawar | last post by:
Hi, I have created a Asp.net Web Application. In this web application I want to use native VC++ dll . I have used "dllImport" atribute. This works fine in Asp.net console Application. While...
11
by: Rolf Welskes | last post by:
Hello, the problem seems to be complex and is in all developments of web-controls which uses own TypeConverter. For this I have here a simple demo-program of the problem: The Control-code: A...
1
by: =?Utf-8?B?VHJlY2l1cw==?= | last post by:
Hello, Newsgroupians: I have created an unmanaged DLL using Visual Studio 2005, which was created in Visual C++. I have some functions in the DLL that I am trying to call. When I "dumpbin...
1
by: elke | last post by:
Hi, I want to use an unmanaged dll in C# .net and I'm having some troubles witch a function that should return an array. I'm new at this, so I don't know what I'm doing wrong. Here is some...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.