|
Replace the ' with '' (that's two ' s)
modified 12-Jul-20 21:01pm.
|
|
|
|
|
|
I usually use the ` character (0x60, grave accent) which has the advantage to be graphically closer than the double quote.
|
|
|
|
|
Thank you - that is a good suggestion.
|
|
|
|
|
I believe I have a simple problem or a novice problem.
If I write a DLL using Borland C++, and want to call another DLL from within the running DLL, what is the format to do so?
Can I get an example?
Problem:
I have a program that calls one DLL to get a piece of data.
Then I use that (let us use an interger ) data to call a 2nd DLL.
What I would like to do is when I call the 2nd DLL, I would like that DLL to call the first DLL to get the interger data and continue to process and then return to the original calling program.
This appears to be a simple call format inside the 2nd DLL, but I am going in circles.
I have been searching the sites, and all problems seem so much more complex than what I am looking for.
Thanks.
|
|
|
|
|
george33027 wrote:
...want to call another DLL
There is no such thing as "calling a DLL." You can dynamically link with another DLL using LoadLibrary() (and then one or more calls to GetProcAddress() ), or you can call a function exported by the DLL regardless of whether you statically or dynamically linked.
george33027 wrote:
What I would like to do is when I call the 2nd DLL, I would like that DLL to call the first DLL to get the interger data and continue to process and then return to the original calling program.
Let me get this straight. The 1st DLL is going to call an exported function within the 2nd DLL which is in turn going to call an exported function within the 1st DLL (to get an integer). Is that right? If not, you'll need to be a bit clearer on which DLL is doing what.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
I guess I got my terminology wrong.
Let me restate, because I think you gave me almost the answer I need.
Thank you so far.
If I make a DLL (call it number1.DLL) whose export will be a constant, or the DLL will return a constant.
Now I make a 2nd DLL let us call it number2.DLL.
In number2.DLL I want to link number1.DLL so that I can get that constant to use.
So how would you set up the program.cpp file to like the number1.DLL ?
#include <windows.h>
extern "C"
__export WINAPI test()
{
// code to get the constant from \path\number1.DLL
return(Number from number1.dll);
}
How would you put in the LoadLibrary() to get to a specific path and number1.DLL.
Then how would you use the GetProcAddress() to get this constant.
|
|
|
|
|
Let me recompose the statement in a bit different manner..
You have program, call it Proggy, for now. Proggy loads only the second DLL, and uses GetProcAddress to get the exported function. When this exported function is called, the second DLL loads the first DLL in order to retrieve the required constant. Then the second DLL returns this constant to Proggy.
Is this logic correct ? If so, the steps to implement it are as follows:
1. Create the first DLL. It has a function funcXYZ that is exported and returns the constant.
2. Create the second DLL. It has a function func123 that is also exported, and returns a number.
3. The function inside the second DLL uses LoadLibrary to load the first DLL, and then GetProcAddress to obtain access to the function exported by the first DLL.
4. This function-pointer is used to call the exported function.
5. As you now have the number, you can use FreeLibrary to unload the first DLL. At this point, the function pointer becomes invalid.
6. Return the number from the second DLL's exported function just like you'd return any other number. See here, that in the second DLL's function, you need to create a local variable that will hold a copy of the constant delivered from the first DLL.
Here's a code example of the first DLL's function:
__declspec(dllexport) int ReturnConstant(void)
{
return TheConstant;
} Here is the function in the second DLL:
__declspec(dllexport) int GetNumber(void)
{
HMODULE hMod = LoadLibrary("Number1.DLL");<DIV>
int (*ptrFunc)(void) = (int (*)(void)) GetProcAddress(hMod, "ReturnConstant");<DIV>
const int theConstant = ptrFunc();<DIV>
FreeLibrary(hMod);
ptrFunc = NULL;<DIV>
return theConstant;
} Note that I've used a direct pointer-to-function declaration with GetProcAddress . It might be easier for you to use a typedef to declare the type first. See MSDN for an example of how typedef is used to declare pointer-to-function types.
Note also that I've used Microsoft Visual C++ to declare the exported functions. The __declspec identifier is not available in Borland C++, you must use some other keyword, like the __export .
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Thank you Thank you Thank you.
This worked perfectly.
Thank you Antti.
One more question, is there anyway to put in a path in the LoadLibrary(path"Numer1.DLL");
All works well if the dll is in the windows folder, but I would like to put the first DLL with my other DLL's.
Is this possible within the def ?
|
|
|
|
|
The LoadLibrary will search for the DLL, if the path is not specified, in the following order:
1. Current directory
2. Windows\System
3. Other misc directories
You can specify a path into the string, but for all backslash characters, you need to use a double-backslash, i.e. "C:\\Windows\\System\\Numer1.DLL". If you are running inside the first DLL and wish to know the directory where you are now, use GetModuleFileName . Then parse this path, adding or removing file names as necessary to identify the path/name of the second DLL.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Antti;
You are good!
On another topic.
How would you get specific computer information, like the maker of the motherboard, bios date, serial number of hardware, etc ?
Basically, a simple way to identify a specific computer, without going to alot of trouble.
Using basic PC's, using MS Windows (all versions)
|
|
|
|
|
You should use Windows Management Instrumentation (WMI).
It provides access to details of what processor, OS, motherboard and other such components a computer has. Many programs like SiSoft Sandra use WMI to get details of a computer in an orderly fashion.
I'll provide a link to the MSDN Library, on the WMI start page here[^]. You should read and familiarize yourself before actually using them, because incorrect usage may lead to problematic situations.
The most interesting things you can query from the WMI (and the ones you're interested in) are located here[^].
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Now I would like to get text information from an internet site.
Do you have an example of how I would connect to an internet site and download a specfic file?
Assume that I am connected to the internet and I am using another program to download data.
Now when in my DLL, I need some specific information, I would like to connect to a specific site (I know the IP address and folder)and download a file and check some text information.
Can I get an example.
|
|
|
|
|
I wish to read and write NTFS extended file attributes in C++.
I was very surprised that I did not find this information readily available.
First I am assuming that NTFS extended file attributes are name-value pairs of
strings. Is this correct? May I create a name and a value and attach that to
a file as an extended file attribute?
Presuming that that is correct, how do I
1) Determine whether a file supports extended file attributes (resides
on a NTFS drive)
2) Read the extended file attributes
3) Set the extended file attributes
I am in a VC++ 6 environment.
Thanks
|
|
|
|
|
gokings wrote:
...NTFS extended file attributes...
Just so we are on the same page here, what is your definition of "NTFS extended file attributes."
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
GetVolumeInformation() will tell you if the driver is NTFS.
GetFileSecurity() can also tell you, if it fails you're not on NTFS and will get the "Security Information" if this is what you mean by extended.
GetFileAttributes() works on basic FAT r/w/h/s attributes.
GetFileAttributesEx() gets a few more attributes.
GetFileInformationByHandle() gets a bunch of crap.
Or are you talking about "extended attributes" as in:
Extended Attribute Information
Used by file servers that are linked with OS/2 systems. This attribute type isn't useful to Windows NT.
Extended Attributes
Used by file servers that are linked with OS/2 systems. This attribute type
|
|
|
|
|
Thanks for the info!
I have found that NTFS does not support extended attributes in the sense that OS/2 does (unfortunately, in my opinion).
However, it does support multiple data streams. Normally, the default (unnamed) data stream is accessed.
I can use a named data stream to achieve my purpose, though I have to jump through a few hoops.
Thanks for the feedback!
|
|
|
|
|
How can I get the program folder?
|
|
|
|
|
I don't know if there's an actual API call on this or not, but you can always pluck this out of the registry. It's always in the same place on any version of Windows:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\ProgramFilesDir
-OBRon
|
|
|
|
|
Thanks,
I think it will work but it will be more code but thats ok.
|
|
|
|
|
Do you mean the program files folder? or the folder that your program is running from?
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
The Program files folder.
|
|
|
|
|
The problem is that the program files folder can be on several drives. I have MS office installed on my D drive and the installer created a program files folder by default. You'd have to search all fixed drives to make sure that it does not exists on any of them.
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
Have you tried looking at the SHGetFolderPath(), SHGetFolderLocation(), SH* functions?
|
|
|
|
|
GetModuleFileName()
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|