none
A time issue RRS feed

  • Question

  • Hi all:

    I wanna call _localtime_s of Win32API in my managed code, How to do that? Please refer to my code with "DllNotFoundException" exception:

    [DllImport("MSVCR90D.Dll")]
    public static extern Int32 localtime_s(ref TM tm, IntPtr time64);

    Exception:
    Additional information: Unable to load DLL 'MSVCR90D.DLL': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

    I know i am leading a wrong dll file, could anyone tell me the correct file name that export localtime_s of win32 api?
    Thanks,
    Simon
    Friday, March 12, 2010 8:03 AM

Answers

  • _localtime_s is not part of the Win32 API, it's from the VC runtime library. I'd recommend writing a C#-friendly wrapper DLL in C++ if you really need to call that function. That will ensure that the CRT gets initialized properly.

    Note that for the 32-bit version, the last parameter should be an int. And the calling convention for CRT functions is Cdecl.

    Mattias, C# MVP
    Friday, March 12, 2010 11:12 AM
    Moderator

All replies

  • If i call localtime in the msvrt.dll, i encountered the loader lock question. Surely, i can remove it from the setting, but the crash will be raised.
    Friday, March 12, 2010 9:54 AM
  • does anyone know that? In one word, how can i call "localtime_s" in the manage code(c#) ?
    Friday, March 12, 2010 9:55 AM
  • The "D" in MSVCR90D.DLL stands for "Debug". You should use "MSVCR90.DLL" as the debug version may not be available in the target system.
    -- Blog: http://geeklyeverafter.blogspot.com/
    Friday, March 12, 2010 10:30 AM
  • _localtime_s is not part of the Win32 API, it's from the VC runtime library. I'd recommend writing a C#-friendly wrapper DLL in C++ if you really need to call that function. That will ensure that the CRT gets initialized properly.

    Note that for the 32-bit version, the last parameter should be an int. And the calling convention for CRT functions is Cdecl.

    Mattias, C# MVP
    Friday, March 12, 2010 11:12 AM
    Moderator
  • Thanks, you save my day!
    Saturday, March 13, 2010 3:19 AM
  • Hi Simon,

    Glad to see that you got it resolved, by the way, if you can mark those useful replies as answers, other community members who encounter similar issue will benefit a lot from this thread.


    Sincerely,
    Eric
    MSDN Subscriber Support in Forum
    If you have any feedback of our support, please contact msdnmg@microsoft.com.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Monday, March 15, 2010 3:18 AM
  • I had marked the answer of Mattias.
    Tuesday, March 16, 2010 11:42 PM