DLL hinstance with in the same dll - dll

I have an MFC dll with is used in an application.This Dll doesn't have DLLMain function.Now how do i retrieve hinstance of the said dll with in the dll?I am using VS 2010.

GetModuleHandle function will return the HINSTANCE of the dll or the exe.
Pass the name of your dll as the first argument.
https://msdn.microsoft.com/en-us/library/windows/desktop/ms683199(v=vs.85).aspx

Related

Generate tlb from dll in same directory under another name

I want to make a type lib (tlb) having another name than dll:
c:\windows\Microsoft.NET\Framework\v4.0.30319\regasm.exe "c:\program files (x86)\sample_program\Library.dll" "c:\program files (x86)\sample_program\TypeLibname.tlb" /codebase
When executing this line in Powershell, no errors occur.
Microsoft .NET Framework Assembly Registration Utility 4.7.3056.0
für Microsoft .NET Framework, Version 4.7.3056.0
[...]
Types have been registered
So a tlb must have been generated. Though the tlb is put everywhere, but not in the desired directory "c:\program files (x86)\sample_program\"
Any idea ?
Thank you !
All the best,
Stephan
Just had to insert /tlb and change the expression into:
c:\windows\Microsoft.NET\Framework\v4.0.30319\regasm.exe "c:\program files (x86)\sample_program\Library.dll" /tlb:TypeLibname.tlb /codebase

Names for DLLImport when moving C# from Unity script to Mono DLL

I have a working Unity C# script which calls into a native iOS static library. I would like to move the C# code from the Unity script attached to a scene object and into a new Mono DLL. I'll then rewrite the Unity C# script to call the Mono DLL. I'm unsure how to name the DLL representing the imported native iOS static library (the .a file)
In the C# script I have this external declaration:
[DllImport("__Internal")]
private static extern int square(int x);
What should the DLL name be when I copy those lines over to the Mono DLL?
Just to turn #Droppy's comments into an answer, the C# I have in the Unity script:
[DllImport("__Internal")]
private static extern int square(int x);
works without change as part of a Mono DLL imported as an asset into a Unity project. I did not need to search for a more specific name than the Unity magic "__Internal".
(N.B. Example code is available here.)

Is .lib file required for applications with load time Dynamic linking?

It says that in case you use load time dynamic linking with DLL it looks up functions entries and other things from a .lib file.
However I cannot find any information on whether this .lib file is required only at compile time or if it needs to be shipped with the program executable for it to work
Lib files are linked into final executable or DLL - so no, you don't need to ship Lib files to users of the application.
If you are building DLL you may provide lib file for your DLL to developers to simplify using of your DLL.

MSVC 2008 - Unresolved External errors with LIB but only with DLL, not with EXE project

I have a DLL that I am trying to link with a libjpeg LIB using MSVC 2008 that is generating Unresolved External Symbol errors for the libjpeg functions. I also have a test project that links with the exact same libjpeg library file and links without error and runs fine too.
I have triple-checked my LIB path and dependent LIBS list settings and literally copy and pasted them from the EXE project to the DLL project. I still get the errors. I do have the libjpeg include headers surrounded by extern "C" so it is not a name mangling issue and the unresolved external warnings show the "missing" libjpeg functions as undecorated (just a leading underscore and the # sign parameter byte count suffix after each name).
What could make the linker with the DLL project be unable to find the functions properly when the test EXE project has no trouble at all? I'm using the pre-compiled 32-bit static multi-threaded debug library which I downloaded from ClanLib.
Thanks,
Robert
After a lot of experimentation I found the solution. It turns out the problem was due to a difference in the calling convention used by the DLL and the LIB projects (In MSVC 2008 this is set on the Project Properties, "Configuration Properties -> C/C++ -> Advanced" setting. The DLL project was set to __stdcall and the LIB was __cdecl. Recompiling LIBJPEG with __stdcall fixed the problem.

DLL Needed For Excel VBA Sleep()?

When using:
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Is it required to have some sort of DLL? If so, which DLL and where can I obtain it?
kernel32.dll is part of Windows, and as such will be on every Windows OS based machine.