glen
glen

Reputation: 23

How to initialize msvcrt.dll?

If I do a LoadLibrary("msvcrt.dll") do I need to initialize the CRT somehow? Section 2 in the following document seems to say that I do, but I just get an undefined symbol error for _CRT_INIT when I try to call _CRT_INIT:

http://support.microsoft.com/kb/94248

Edit: I should have said that this is for a program that dynamically loads all the dlls that it uses, hence the call to LoadLibrary("msvcrt.dll").

Upvotes: 2

Views: 3982

Answers (4)

Clifford
Clifford

Reputation: 93566

The link you referenced refers to using CRT_INIT() only when "Using the CRT Libraries When Building a DLL", and even then it is only one of two alternatives; the first probably being preferable in most cases.

Upvotes: 0

please delete me
please delete me

Reputation:

If you're working in C++, have you declared _CRT_INIT as extern "C"?

Have you tried using the DUMPBIN utility ( http://support.microsoft.com/kb/177429 -- if you haven't your PATH up yourself, you'll have to use the Visual Studio Command Prompt I think) with the /EXPORTS switch to see which functions are available from the CRT DLL, just to double check?

If you get stuck, VS2005 and earlier (and presumably later...) come supplied with the source code for the runtime library. For VS2005, this is in VC/crt/src, relative to the VS install folder. It looks like _CRT_INIT is the right name -- see crtdll.c and dllcrt0.c, and it's a C function.

Upvotes: 1

engf-010
engf-010

Reputation: 3929

You must not call _CRT_INIT() but call CRT_INIT() (if you really must)

Upvotes: 0

wallyk
wallyk

Reputation: 57804

Call DllMain() in it. If it relies on the C runtime, it will call CRT_INIT.

But a far better question is if a program is using something in msvcrt, there's no need to explicitly load the dll and initialize it, so why are you doing this?

Upvotes: 4

Related Questions