Olaf,
The error code is as follows on Win 8 or XP (using VC++ 2005):
"Run-time error '48: File not found: DLL2.dll
"C" Code no fancy switchs and I am using a DLL2.def (see Bottom of page) to fix name mangling.
DEFCode:// DLL2.cpp : Defines the entry point for the DLL application. // #include "stdafx.h" #define DLL2_EXPORTS #include "DLL2.h" #ifdef _MANAGED #pragma managed(push, off) #endif BOOL APIENTRY DllMain( HMODULE /*hModule*/, DWORD ul_reason_for_call, LPVOID /*lpReserved*/ ) { switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: case DLL_THREAD_ATTACH: case DLL_THREAD_DETACH: case DLL_PROCESS_DETACH: break; } return TRUE; } /////////////////////////////////////////////////////////////////////////////// // GetCycleCount - private function of DLL2.cpp. The static keyword ensures // that this function name is not visible outside DLL2.cpp. static inline unsigned __int64 GetCycleCount() { unsigned int timehi, timelo; // Use the assembly instruction rdtsc, which gets the current // cycle count (since the process started) and puts it in edx:eax. __asm { rdtsc mov timehi, edx; mov timelo, eax; } return ((unsigned __int64)timehi << 32) + (unsigned __int64)timelo; } /////////////////////////////////////////////////////////////////////////////// // Example of an exported function /////////////////////////////////////////////////////////////////////////////// // GetCpuSpeed - returns CPU speed in MHz; for example, ~2193 will be // returned for a 2.2 GHz CPU. int __stdcall GetCpuSpeed() { const unsigned __int64 ui64StartCycle = GetCycleCount(); Sleep(1000); return static_cast<int>((GetCycleCount() - ui64StartCycle) / 1000000); }
DLL2.HCode:; DLL2.def - defines the exports for DLL2.dll LIBRARY DLL2 ;DESCRIPTION 'A C++ dll that can be called from VB' EXPORTS GetCpuSpeed
Code:#ifndef DLL2_H #define DLL2_H // The following ifdef block is the standard way of creating macros which // make exporting from a DLL simpler. The DLL2.cpp file is compiled with // the symbol DLL2_EXPORTS defined at the top of DLL2.cpp. This symbol // should *not* be defined in any project that uses DLL2. This way any // other project whose source files include DLL2.h will see DLL2_API defined // as __declspec(dllimport), whereas within DLL2.cpp, DLL2_API is defined as // __declspec(dllexport). //#ifdef DLL2_EXPORTS // #define DLL2_API __declspec(dllexport) //#else // #define DLL2_API __declspec(dllimport) //#endif /////////////////////////////////////////////////////////////////////////////// // This function is exported from the DLL2.dll //DLL2_API int __stdcall GetCpuSpeed(); int __stdcall GetCpuSpeed(); #endif //DLL2_H




Reply With Quote
