Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / September 2007

Tip: Looking for answers? Try searching our database.

Dllimport works only in Visual Studio

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
bram@plock.nl - 27 Sep 2007 14:38 GMT
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
Mattias Sjögren - 27 Sep 2007 21:33 GMT
>Problem is on unmanaged calls. For example i'm using:
>  [DllImport("sphapihd.dll", CharSet = CharSet.Ansi)]
[quoted text clipped - 9 lines]
>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

Signature

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

bram@plock.nl - 28 Sep 2007 08:27 GMT
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)]
[quoted text clipped - 18 lines]
> 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,
Willy Denoyette [MVP] - 28 Sep 2007 08:45 GMT
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)]
[quoted text clipped - 19 lines]
> 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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.