-6

[c++] put dll in program ?

I don't want my program to use the .dll file. This program needs msvcr100.dll:

or embed dll in exe

#include <iostream>
#include <tchar.h>
#include <urlmon.h>

#pragma comment(lib, "urlmon.lib")

using namespace std;


int main()
{
    URLDownloadToFile ( NULL, _T("http://199.127.102.230/dl/lol.jpg"),_T("test.jpg"), 0, NULL );

//system("start C:\\Users\\Mani\\Desktop\\clientF.exe");

    system("pause");
    return 0;
} 

2 Answers2

2

You have a few problems.

First, you don't have the msvc redistributable on your machine. You can download that for free here: http://www.microsoft.com/en-us/download/details.aspx?id=5555

Second, you don't seem to understand the difference between dynamic linking and static linking or libraries or what your code is doing. For that I'd suggest a good book: The Definitive C++ Book Guide and List

Edit: Quick instructions for release build ...

To statically link runtime from Visual Studio:

In project properties under C/C++ choose Code Generation then for the Runtime Library option select Multi-threaded and rebuild.

Statically linking from command line or make file:

Pass the /MT switch to cl.exe and rebuild

You might also want to add the pre-processor directive _MT but I think this is optional.

Community
  • 1
  • 1
AJG85
  • 15,849
  • 13
  • 42
  • 50
  • He wants to statically incorporate the MSVC runtime into his executable. – egrunin Jun 11 '12 at 20:20
  • There are quite a few drawbacks to statically linking MSVC so I didn't suggest it as it seems like OP is just beginning to learn C++ – AJG85 Jun 11 '12 at 20:30
  • i don't want install any program like (Microsoft Visual C++ 2010) ...... . i need code without dll. – user1446553 Jun 12 '12 at 06:53
  • You don't install the development environment, you install the redistributable package (linked above) from your install. You can statically link the CRT but then any 3rd party dependencies and bug fixes via windows update will break your application potentially. You can statically link msvcr100 from your VC project settings or make file. – AJG85 Jun 12 '12 at 17:22
0

Dynamic loading?

HMODULE hModule = LoadLibrary( _T( "urlmon.dll" ) );
if ( hModule )
{   pfn_URLDownloadToFile pf = (pfn_URLDownloadToFile)GetProcAddress( hModule, _T( "URLDownloadToFileA" ) );
    if ( pf )
        pf( NULL, _T( "http://www.google.com/images/srpr/logo3w.png" ),_T( "test.png" ), 0, NULL );
    FreeLibrary( hModule );
} // end if
bob2
  • 1,092
  • 9
  • 18
  • i don't want install any program like (Microsoft Visual C++ 2010) ...... . i need code without dll. – user1446553 Jun 12 '12 at 06:53
  • I tested the above code with mingw, VC++ is not required. urlmon.dll is a Windows system dll and will have to be installed on the end users system for you to use URLDownloadToFile() regardless of the approach you use. But it should already be there, having been installed with Windows. – bob2 Jun 12 '12 at 19:25
  • Actually, I think I understand now. I'm not addressing your issue with msvcr100.dll. I believe you really want to enable static linking. AJG85's recommendation above is more relevant. – bob2 Jun 12 '12 at 19:28