|
-
May 24th, 2008, 11:04 AM
#1
Question about linking in VS 2008.
Hello all. I was wondering, how could I link a lib file to my file, so I wont have to use its DLL. Is this posible at all?
Thanks in advance!
-
May 24th, 2008, 01:03 PM
#2
Re: Question about linking in VS 2008.
Give this a read - come back here if you have any questions.
http://msdn.microsoft.com/en-us/libr...33(VS.80).aspx
gg
-
May 24th, 2008, 01:39 PM
#3
Re: Question about linking in VS 2008.
It didnt tell me much.. Just stuff I already knew.. I am using the LIB file as a resolver, but it will still ask for the DLL file when the process will start.
Same as for LoadLibrary func. the proc` will ask for the DLL when loading.
What I wanted to do is, to link the dll with the proc so I wont have to load it when I start the proc. (I wont have to include the DLL file on the relase package).
Thanks in advance!
-
May 24th, 2008, 02:09 PM
#4
Re: Question about linking in VS 2008.
 Originally Posted by SliderMan
Same as for LoadLibrary func. the proc` will ask for the DLL when loading.
????
You need *no* import library if you're using LoadLibrary. Therefore the application will *not* ask for the DLL when the app starts. I don't know where you got that information from.
You must still have the lib file in your project settings. If you're using LoadLibrary, then get rid of the .lib file and rebuild your application.
Regards,
Paul McKenzie
-
May 24th, 2008, 03:21 PM
#5
Re: Question about linking in VS 2008.
LoadLibrary will make the DLL functions a part of my executable?
EDIT:
Here I used LoadLibrary and it still asking for the dll
Code:
LoadLibrary(_T("pircbotcpp-mt"));
Code:
This application has failed to start because pircbotcpp-mt.dll was not found. blah blah reinstalling....
Thanks in advace guys.
Last edited by SliderMan; May 24th, 2008 at 04:06 PM.
-
May 24th, 2008, 06:38 PM
#6
Re: Question about linking in VS 2008.
Remove any reference to the import library in your project settings - probably "pircbotcpp-mt.lib"
Remove any "#pragam comment(lib "pircbotcpp-mt.lib")" from the headers and source code.
Once those are gone, the DLL should no longer be required to start the EXE.
gg
-
May 24th, 2008, 07:15 PM
#7
Re: Question about linking in VS 2008.
 Originally Posted by SliderMan
LoadLibrary will make the DLL functions a part of my executable?
No. LoadLibrary() is just an API function. It's just a function call so it has nothing to do with what gets added to your executable.
EDIT:
Here I used LoadLibrary and it still asking for the dll
Code:
LoadLibrary(_T("pircbotcpp-mt"));
That is because your project is still not set up correctly.
Let's make it easy:
Create a brand new Win32 project. Better yet, make it a console project. Now add one CPP file to the project -- nothing else...
Code:
#include <windows.h>
int main()
{
HMODULE h = LoadLibrary(_T("pircbotcpp-mt"));
if ( h )
FreeLibrary( h );
}
This simple 3 line program will prove to you that you do not need any lib files. You will not get any message saying anything about the application failing to start. You will get an error if the LoadLibrary() call does not find your DLL.
Regards,
Paul McKenzie
-
May 24th, 2008, 10:45 PM
#8
Re: Question about linking in VS 2008.
Ok. Thanks alot for your` help guys. =)
-
May 24th, 2008, 11:08 PM
#9
Re: Question about linking in VS 2008.
I think something has gotten lost....
As I read the original post, the OP would like the DLL to actually be statically linked into the .EXE so that it functional as if it were a static LIB (ie all of the code is contained inside the EXE itself, no additional files to distribute).
BEfore going down this path, I would loke to hear from the OP to see if this is indeed what he/she wants.....
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions 
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
-
May 24th, 2008, 11:54 PM
#10
Re: Question about linking in VS 2008.
 Originally Posted by TheCPUWizard
I think something has gotten lost....
As I read the original post, the OP would like the DLL to actually be statically linked into the .EXE so that it functional as if it were a static LIB (ie all of the code is contained inside the EXE itself, no additional files to distribute).
BEfore going down this path, I would loke to hear from the OP to see if this is indeed what he/she wants.....
That is true
Code:
no additional files to distribute
I want to give out ONLY the EXE file. It should be working without the DLL for that porpuse.
I wanted to link my EXE, so windows wont look for the dll file and load it when i run the EXE. But for that to work ill have to get ALL the exports list and use GetProcAdd(); right? or this wont work as well?
Last edited by SliderMan; May 24th, 2008 at 11:56 PM.
-
May 24th, 2008, 11:58 PM
#11
Re: Question about linking in VS 2008.
Perhaps Delay-Loading the DLL would help...
http://msdn.microsoft.com/en-us/library/151kt790.aspx
>> I want to give out ONLY the EXE file.
>> ...ill have to get ALL the exports list and use GetProcAdd()
Do you want to call functions in this DLL? But only if the DLL exists on the PC?
gg
Last edited by Codeplug; May 25th, 2008 at 12:02 AM.
-
May 25th, 2008, 12:05 AM
#12
Re: Question about linking in VS 2008.
 Originally Posted by Codeplug
Perhaps Delay-Loading the DLL would help your situation.
HOW???? The DLL would still have to be deployed to the target machine, which the OP jhust stated was NOT desired....
Back to the issue.
First, if the DLL was crerated by a third party, it is probably ILLEGAL to attempt to include it in your EXE.
Second, It is typically best to actually distribute the information as an EXE with DLL's. If you want to make thing simplier to deploy, simply crerate a Setup project and create a proper install.
If you MUST distribute one EXE, then you could embedd the DLL inside the EXE as a binary resource. Then at runtime extract it to a temporary location and utilize one of the methods listed above.
Finally (and this is 99.995% odss of being illegal if you did not write the DLL), you can revers compile it, and then create a proper static LIB....
But if you DID crreate the DLL, why not just re-compile to a static DLL and save all this grief????
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions 
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
-
May 25th, 2008, 12:16 AM
#13
Re: Question about linking in VS 2008.
>> HOW????
Simple. Have the linker delay-load the DLL. Only call DLL functions *if* the DLL exists on the PC.
>> Do you want to call functions in this DLL? But only if the DLL exists on the PC?
Delay loading is only really useful if the answers are Yes and Yes. Otherwise, TheCPUWizard has listed the remainder of your options.
gg
Last edited by Codeplug; May 25th, 2008 at 12:18 AM.
-
May 25th, 2008, 12:31 AM
#14
Re: Question about linking in VS 2008.
>>Finally (and this is 99.995% odss of being illegal if you did not write the DLL), you can revers compile it, and then create a proper static LIB....
How can I use that? I can just ask for the source.. Its open source all of that project im using so, I guess it wont be a biggie to email the creator and ask for the DLL source... How can I create a static lib? will this help me?
Last edited by SliderMan; May 25th, 2008 at 03:09 AM.
-
May 25th, 2008, 12:57 AM
#15
Re: Question about linking in VS 2008.
You could go through the trouble of linking the source staticaly... or
>> you could embedd the DLL inside the EXE as a binary resource
which is probably *much* easier....
Code:
bool SaveResourceFile(int res_id, const wchar_t *pathname)
{
HMODULE hmod = GetModuleHandle(0);
HRSRC hr = FindResource(hmod, MAKEINTRESOURCE(res_id), RT_RCDATA);
if (!hr)
{
LogMessage(L"FindResource(%d) failed, le = %u", res_id, GetLastError());
return false;
}//if
DWORD hrsz = SizeofResource(hmod, hr);
if (!hrsz)
{
LogMessage(L"SizeofResource() failed, le = %u", GetLastError());
return false;
}//if
HGLOBAL hg = LoadResource(hmod, hr);
if (!hg)
{
LogMessage(L"LoadResource() failed, le = %u", GetLastError());
return false;
}//if
void *pfile = LockResource(hg);
if (!pfile)
{
LogMessage(L"LockResource() failed, le = %u", GetLastError());
return false;
}//if
FILE *f = _wfopen(pathname, L"wb");
if (!f)
{
LogMessage(L"Failed to open %s for writting, le = %u",
pathname, GetLastError());
return false;
}//if
bool res = (fwrite(pfile, hrsz, 1, f) == 1);
fclose(f);
if (!res)
{
LogMessage(L"Failed to write resource data to file, le = %u",
GetLastError());
}//if
return res;
}//SaveResourceFile
/*
In your RC file:
IDR_DLL RCDATA DISCARDABLE "pircbotcpp-mt.dll"
*/
gg
Last edited by Codeplug; May 25th, 2008 at 01:00 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|