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

Why does C# call an external DLL directly vs. indirectly in the same app?

What causes C# to generate code to call the same external DLL 2
different ways?

At one point in the app, it calls the entry point like this
(disassembled) and it bombs with a null reference:
00000064 call dword ptr ds:[086F1350h]

At another point in the same app, it calls the exact same entry point
like this and it works:
00000051 call 00A5B073

These are calls to the EXACT SAME external DLL from 2 different
classes in the same app. Both calls in C# have the exact same types
of args.

Details if you want them:

The DLL entry point is declared this way:
public class GeoTools
{
[DllImport(DLLName, EntryPoint="_CopyPic@20", ExactSpelling=true)]
public static extern GTResult CopyPic(int DestFileNum, int SrcFileNum,
int PicNum, int FieldNum, int CopyType);
}

Code excerpts (disassembly):

Excerpt 1 bombs at the CALL below:
if ((LastError = GeoTools.CopyPic(-1, m_nStreamNum, PicNum, 0,
0)) != GTResult.Success)
00000050 mov dword ptr [ebp-14h],esi
00000053 mov ebx,dword ptr [esi+50h]
00000056 push dword ptr [ebp-8]
00000059 push 0
0000005b push 0
0000005d mov edx,ebx
0000005f mov ecx,0FFFFFFFFh
00000064 call dword ptr ds:[086F1350h]
0000006a mov ebx,eax
0000006c mov dword ptr [ebp-10h],ebx
0000006f mov eax,dword ptr [ebp-14h]
00000072 mov edx,dword ptr [ebp-10h]
00000075 mov dword ptr [eax+3Ch],edx
00000078 cmp dword ptr [ebp-10h],1
0000007c je 00000094

Excerpt 2 works perfectly; note how it calls the DLL differently:
if ((LastError = GeoTools.CopyPic(-1, m_nStreamNum, PicNum, 0,
0)) != GTResult.Success)
0000003d mov dword ptr [ebp-14h],esi
00000040 mov ebx,dword ptr [esi+54h]
00000043 push dword ptr [ebp-8]
00000046 push 0
00000048 push 0
0000004a mov edx,ebx
0000004c mov ecx,0FFFFFFFFh
00000051 call 00A5B073
00000056 mov ebx,eax
00000058 mov dword ptr [ebp-10h],ebx
0000005b mov eax,dword ptr [ebp-14h]
0000005e mov edx,dword ptr [ebp-10h]
00000061 mov dword ptr [eax+44h],edx
00000064 cmp dword ptr [ebp-10h],1
00000068 je 00000080
Nov 17 '05 #1
1 1482

"stevo" <st************@hotmail.com> wrote in message
news:r6********************************@4ax.com...
What causes C# to generate code to call the same external DLL 2
different ways?


I'd advise posing this question on microsoft.public.dotnet.framework.clr, as
this isn't a C# issue and you have a better shot at finding someone who
knows enough about the JIT to answer it. The JIT is generating this code for
some reason, and unless you ommited a detail it is almost certainly a bug,
but unless the IL generated differs, I don't think the C# compiler has any
direct relation.
Nov 17 '05 #2

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

Similar topics

1
by: terrencel | last post by:
I was told to look at some old C code that was ported to C++. One of the file is like: ========================================= CPPClass* someCPPVar = NULL; extern "C" {
7
by: John Grandy | last post by:
make a call to XML Web Service WebMethod ... returns object myArray with no error ... myArray contains objects of type StringKeyStringValue runtime error occurs on accessing properties of...
51
by: Tony Sinclair | last post by:
I'm just learning C#. I'm writing a program (using Visual C# 2005 on WinXP) to combine several files into one (HKSplit is a popular freeware program that does this, but it requires all input and...
55
by: Zytan | last post by:
I see that static is more restricted in C# than in C++. It appears usable only on classes and methods, and data members, but cannot be created within a method itself. Surely this is possible in...
8
by: mdh | last post by:
May I ask this. Given the declaration: int myf( int, int); and a function pointer: (*fp)=int myf(int, int); where I am initializing fp to point at myf....or trying to..
13
by: Lars Willich | last post by:
As far as I know I can override the php settings for a certain branch of the whole directory tree by putting a additional, new php.ini in this directory. Is this true ? If I assign in this new...
8
by: zionist.news | last post by:
The world have been after Bill Gates for no reason. The richest group was and remains the Zionist jew Rothschilds family who own HALF the worlds total wealth through numerous frontmen zionists. ...
162
by: Sh4wn | last post by:
Hi, first, python is one of my fav languages, and i'll definitely keep developing with it. But, there's 1 one thing what I -really- miss: data hiding. I know member vars are private when you...
32
by: Stephen Horne | last post by:
I've been using Visual C++ 2003 for some time, and recently started working on making my code compile in GCC and MinGW. I hit on lots of unexpected problems which boil down to the same template...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.