Dllimport works only in Visual Studio

  • Thread starter Thread starter bram
  • Start date Start date
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
 
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
 
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,
 
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.
 
Back
Top