Board index » cppbuilder » Re: DLL Question

Re: DLL Question


2003-06-27 11:58:09 PM
cppbuilder15
I believe I have solved my problem (in a strange way), Thanks to all who
pointed me in the right directions,
I'm blind sometimes <grin>.
The problem started with the program crashing before it even got to Main().
I have a DLL (with source) that also calls routines in another DLL (from a
chip manufacturer and M$ VC++)..
Adding some MessageBox(NULL, "Process Attach to DLL Xyz", MB_OK) code to the
DLL that I have source for showed me that I was crashing after the DLL's
starting loading.
I also used the Dependancy Walker (from another thread)
www.dependencywalker.com to see where and how things got loaded.
The problem arose from the DLL not loading, though no error message was
seen, just the De{*word*81} popping up with a Debug Window.
I had used IMPDEF to create a .DEF file for the DLL from the chip
manufacturer and it created a list of all the functions from that DLL ok.
(_funcxyz = funcxyz ;funcxyz)
Adding the DEF file to the project resulted in some strange errors something
like "Attempting to Export a Non-Public Function".
(From the CPPB6 Dev Guide, I tried changing the def file to funcxyz=_funcxyz
;funcxyz and got the same error).
After running the DEF file through IMPLIB and using the resultant LIB file
with the project instead of the DEF file made everthing work ok.
I would have thought that either method would work...
"Ed Mulroy [TeamB]" < XXXX@XXXXX.COM >wrote in message
Quote
If the DLL is implicitly linked DllMain or DllEntryPoint are called by the
Windows loader phase as it collects the items involved in loading the
program. This normally occurs prior to execution arriving at your
program's
main or WinMain function.

If the DLL is explictly loaded the function is also called by Windows but
as
a result of your program's call to LoadLibrary, LoadLibraryEx or
LoadLibraryEx32W.

. Ed

>Midnight Programmer wrote in message
>news:3efa262c$ XXXX@XXXXX.COM ...
>
>Sorry for the incorrect terminology... I was using the BCPP6
>Developers guide terminology from Chapter 16... "Linking DLL's
>Statically - To understand how to statically link a DLL....."
>
>When the Application (Gui or Console) starts and I 'Implicitly
>linked' by using an Import Library (I don't know here, I compiled
>the DLL and it made the DLL and a LIB file) I assume that the
>DLLMain() or DLLEntryPoint() are the only functions that
>are called (to the DLL) by the underlying operating system?
>Sound about right?


 
 

Re:Re: DLL Question

On Fri, 27 Jun 2003 08:58:09 -0700, "Midnight Programmer" < XXXX@XXXXX.COM >
wrote:
Quote
The problem arose from the DLL not loading, though no error message was
seen, just the De{*word*81} popping up with a Debug Window.
That's one of the things I never liked about implicit loading
DLLs. When the program starts up if there's an issue it's
more of a hassle to isolate.. whereas if you have a call
to LoadLibrary() then you can easily stick in a breakpoint
to see if the DLL is involved.
I don't like it when my app {*word*99}s out on loading. Too
much stuff going on. Plus it makes a bad impression
when your app doesn't even load.. even though it
can be a minor error easily solved. :)
Glad you got it going.
--
"I don't want to belong to any club that would have me as a member."
-- Groucho Marx
 

Re:Re: DLL Question

It's good hearing that you have solved it, but please keep an eye out for
this:
Quote
I had used IMPDEF to create a .DEF file for the DLL from
the chip manufacturer and it created a list of all the functions
from that DLL ok.
(_funcxyz = funcxyz ;funcxyz)
Under both MS and Borland compilers __stdcall calling convenetion used a
public name exactly as seen in the source and __cdecl (the default) calling
convention added a leading underscore. Of late MS seems to have played
around with that and may not follow that exactly.
If a __stdcall function which has calling parameters is called as if it were
__cdecl then there will be a stack imbalance because both of the calling
program and the function will clear the space for the calling parameters off
of the stack, wiping out return addresses and leaving a glitch which may
wait and show up later in unrelated code. (Also the parameter order is
reversed). If the reverse is done, then nobody clears them off of the
stack, leaving the stack imbalanced which causes similar problems (and
again, calling parameter order is reversed).
If problems creep in consider if the DLL's exported functions really were
__stdcall (aka WINAPI0 or __cdecl.
. Ed
Quote
Midnight Programmer wrote in message
news:3efc6994$ XXXX@XXXXX.COM ...

I believe I have solved my problem (in a strange way),
Thanks to all who pointed me in the right directions,
I'm blind sometimes <grin>.
...
 

{smallsort}

Re:Re: DLL Question

How do you dynamically load a DLL?
I am trying to write a wrapper for a third party DLL and in the
documentation they mention that the DLL must dynamically loaded. Is there a
procedure call to make?
Gilles
 

Re:Re: DLL Question

LoadLibrary....
/Bo
 

Re:Re: DLL Question

I have a question about accessing DLLs and executing their methods.
What I want to know is:
- How do I get a list of functions that reside in a DLL
- How do I get the function parameters and return values
- How do I execute a DLL dynamically if I don't have the lib file (
__declspec(dllimport) ) Code sample would be appreciated
Thank you.
 

Re:Re: DLL Question

Quote
- How do I get a list of functions that reside in a DLL
From the DLL vendor's documentation or with this command
tdump -ee DllName.DLL
Quote
- How do I get the function parameters and return values
From the DLL vendor's documentation
Quote
- How do I execute a DLL dynamically if I don't have the lib file (
__declspec(dllimport) ) Code sample would be appreciated
implib -c DllName.LIB DllName.DLL
Then add DllName.LIB to the project.
DLLs are among the things covered on these pages. While the examples
include the command lines for creating them, the IDE could have also
been used (except for the implib call).
www.mulroy.org/howto.htm
. Ed
Quote
Stephane Baillargeon wrote in message
news:4266cd84$ XXXX@XXXXX.COM ...

I have a question about accessing DLLs and executing
their methods.

What I want to know is:
- How do I get a list of functions that reside in a DLL
- How do I get the function parameters and return values
- How do I execute a DLL dynamically if I don't have the lib file (
__declspec(dllimport) ) Code sample would be appreciated
 

Re:Re: DLL Question

"Stephane Baillargeon" < XXXX@XXXXX.COM >wrote in message
Quote
- How do I get a list of functions that reside in a DLL
The only way is to manually access the EXPORTS table within the DLL's PE
header. Refer to MSDN for details about accessing the PE header:
Peering Inside the PE: A Tour of the Win32 Portable Executable File
Format
msdn.microsoft.com/library/en-us/dndebug/html/msdn_peeringpe.asp
An In-Depth Look into the Win32 Portable Executable File Format
msdn.microsoft.com/msdnmag/issues/02/02/PE/default.aspx
Quote
- How do I get the function parameters and return values
You don't, as that information is not stored anywhere. Not unless you want
to manually decode the raw assembly instructions, but that won't actually
tell you much anyway, unless you implement your own lookup tables for
finding known functions within known libraries.
The only exception to this is ActiveX/COM libraries, which usually (but not
always) have a fully detailed TypeLibrary associated with them.
Quote
- How do I execute a DLL dynamically if I don't have the lib file
You will have to use the LoadLibrary() and GetProcAddress() functions to
obtain pointers to the individual exported functions.
Gambit
 

Re:Re: DLL Question

Try this:
tdump -ee DllName.DLL
Quote
Remy Lebeau wrote in message
news:4266d632$ XXXX@XXXXX.COM ...

>- How do I get a list of functions that reside in a DLL

The only way is to manually access the EXPORTS table within
the DLL's PE header. Refer to MSDN for details about
accessing the PE header:

Peering Inside the PE: A Tour of the Win32 Portable Executable
File Format
msdn.microsoft.com/library/en-us/dndebug/html/msdn_peeringpe.asp

An In-Depth Look into the Win32 Portable Executable File Format
msdn.microsoft.com/msdnmag/issues/02/02/PE/default.aspx
...
 

Re:Re: DLL Question

hello,
is it possible to keep host appl enabled when running dll library?
thx in advance
Borut
Slovenia
 

Re:Re: DLL Question

How does one run a dll library?
What a dll provides is a set of exported functions that you can call. As
far as your program is concerned, they are treated essentially the same as
functions in your own code. You no more run a dll library than you run a
function in your code.
If you wish to do some processing while a function in a dll is also
executing, consider creating a second thread and calling the dll function
while in the context of that new thread. For a way to start a new thread,
look in the help at the description of the functions _beginthread and
_beginthreadNT and in the Win32 help topic Processes and Threads. (Avoid
calling CreateThread - use _beginthread or _beginthreadNT instead.)
. Ed
Quote
Marko Trebovšek wrote in message
news: XXXX@XXXXX.COM ...
hello,

is it possible to keep host appl enabled when running dll library?

thx in advance
Borut
Slovenia
 

Re:Re: DLL Question

Hello,
I use C++ Builder 6.
When I load dll library the host application becomes disabled. Is it
possible to keep host appl enabled when running dll library?
I load my library this way:
Inst_libr = LoadLibrary("ChkZalArt.dll");
typedef void (*MYPROC)(int, AnsiString); //podatki
MYPROC Proces;
if (Inst_libr != NULL)
{
Proces = (MYPROC)GetProcAddress(Inst_libr, "_InvokeMain");
if (Proces == NULL)
MessageBox(NULL,"Napaka v dll knjižnici!", "Opozorilo", MB_OK);
else
(Proces)(0, posl_en); //
}
thx in advance
Borut
Slovenia
--
Bokosoft d.o.o.
www.bokosoft.si
XXXX@XXXXX.COM
tel: 01/546 37 20
fax: 01/546 37 21
 

Re:Re: DLL Question

"Borut" < XXXX@XXXXX.COM >wrote in message
Quote
When I load dll library the host application becomes disabled.
What exactly are you referring to? On which line of code exactly does
it occur? Please be more specific.
Quote
typedef void (*MYPROC)(int, AnsiString); //podatki
There is no calling convention specified in that declaration. I
suggest using __stdcall for the exported function, as it is the most
compatible with Delphi, VC++, and other environments.
And I strongly suggest NOT using AnsiString as a parameter. It is not
a standard data type that non-Borland environments will recognize.
Gambit
 

Re:Re: DLL Question

What I was trying to say is that when I run or load dll library I can't work
with main (host appl) any more, because it is dissabled.
Sorry i forget to say, that this dll has FORMS and when I run dll it shows a
form...
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote

"Borut" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...

>When I load dll library the host application becomes disabled.

What exactly are you referring to? On which line of code exactly does
it occur? Please be more specific.

>typedef void (*MYPROC)(int, AnsiString); //podatki

There is no calling convention specified in that declaration. I
suggest using __stdcall for the exported function, as it is the most
compatible with Delphi, VC++, and other environments.

And I strongly suggest NOT using AnsiString as a parameter. It is not
a standard data type that non-Borland environments will recognize.


Gambit