Добрый день.
Есть MSVC2010 на winXP.
Создаю в MSVC2010 DLL с именем example_load_dll.dll.
Потом создаю в MSVC2010 приложение, которое загружает эту DLL.
После загрузке DLL с помощью LoadLibrary читаю GetLastError.
GetLastError возвращает значение 127, что означает "не найдена указанная процедура".
Подробнее, что именно есть:
Есть DLL, которая ничего не делает. Эта DLL создана в MSVC2010 визардом для DLLек.
// dllmain.cpp : Defines the entry point for the DLL application.
#include "stdafx.h"
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;
}
// example_load_dll.cpp : Defines the exported functions for the DLL application.
//
#include "stdafx.h"
#include "example_load_dll.h"
// This is an example of an exported variable
EXAMPLE_LOAD_DLL_API int nexample_load_dll=0;
// This is an example of an exported function.
EXAMPLE_LOAD_DLL_API int fnexample_load_dll(void)
{
return 42;
}
// This is the constructor of a class that has been exported.
// see example_load_dll.h for the class definition
Cexample_load_dll::Cexample_load_dll()
{
return;
}
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#pragma once
#include "targetver.h"
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
// Windows Header Files:
#include <windows.h>
// TODO: reference additional headers your program requires here
#pragma once
// Including SDKDDKVer.h defines the highest available Windows platform.
// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and
// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.
#include <SDKDDKVer.h>
// The following ifdef block is the standard way of creating macros which make exporting
// from a DLL simpler. All files within this DLL are compiled with the EXAMPLE_LOAD_DLL_EXPORTS
// symbol defined on the command line. This symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see
// EXAMPLE_LOAD_DLL_API functions as being imported from a DLL, whereas this DLL sees symbols
// defined with this macro as being exported.
#ifdef EXAMPLE_LOAD_DLL_EXPORTS
#define EXAMPLE_LOAD_DLL_API __declspec(dllexport)
//#define EXAMPLE_LOAD_DLL_API
#else
#define EXAMPLE_LOAD_DLL_API __declspec(dllimport)
//#define EXAMPLE_LOAD_DLL_API
#endif
// This class is exported from the example_load_dll.dll
class EXAMPLE_LOAD_DLL_API Cexample_load_dll {
public:
Cexample_load_dll(void);
// TODO: add your methods here.
};
extern EXAMPLE_LOAD_DLL_API int nexample_load_dll;
EXAMPLE_LOAD_DLL_API int fnexample_load_dll(void);
Далее есть приложение, которое тоже ничего не делает, а только загружает DLL.
#include <windows.h>
#include <iostream>
using namespace std;
int main(int argc, char* argv[]){
SetLastError(0);
HINSTANCE hi=LoadLibrary("example_load_dll.dll");
DWORD le=GetLastError();
cout<<endl<<"HINSTANCE ="<<hi;
cout<<endl<<"GetLastError()="<<le;
return 0;
}
После запуска приложения получаю GetLastError()=127.
У меня есть другие DLL (не мои), при загрузке которых GetLastError()=0.
Вопросы:
1. Почему при загрузке возникает GetLastError()=127?
2. Как сделать, чтобы GetLastError() был равен 0?
3. Почему при загрузке других DLL GetLastError() равен 0?
Спасибо