Dllimport works only in Visual Studio

B

bram

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
 
M

Mattias Sjögren

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
 
B

bram

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


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,
 
W

Willy Denoyette [MVP]

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


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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top