LoadLibray找不到指定的模块?

thuers 2004-12-10 10:26:31
HMODULE m_hNewDev = ::LoadLibrary("NEWDEV.dll");

做了一个Storage控制程序,
运行这句就出现找不到指定的模块~!
...全文
274 点赞 收藏 10
写回复
10 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
nscboy 2004-12-10
这是MSDN上LoadLibrary载入DLL的顺序(默认情况)
1.The directory from which the application loaded.
2.The current directory.
3.Windows 95/98: The Windows system directory. Use the GetSystemDirectory function to get the path of this directory.
Windows NT/ 2000: The 32-bit Windows system directory. Use the GetSystemDirectory function to get the path of this directory. The name of this directory is SYSTEM32.

4.Windows NT/ 2000: The 16-bit Windows system directory. There is no function that obtains the path of this directory, but it is searched. The name of this directory is SYSTEM.
5.The Windows directory. Use the GetWindowsDirectory function to get the path of this directory.
6.The directories that are listed in the PATH environment variable.
所以我估计应该和路径无关.
还有检查你的NEWDEV.dll的版本和依存dll是否存在.
我的NEWDEV.dll的版本是5.02195.6754
我的win2k是Professional SP4.


回复
nscboy 2004-12-10
先用OpenFile,看看是否也报告这个错误
找到NEWDEV.dll这个文件,然后用Depends看看其依存的DLL是否都存在.
有时候,以来的DLL不存在也会使得LoadLibray失败
回复
oyljerry 2004-12-10
绝对路径查找...
回复
thuers 2004-12-10
GetLastError();
错误代码,找不到指定的模块~!

LoadLibray不是可以查找C:\WINNT\system32(系统目录下的文件啊)。。。。。

我想可能是程序的问题,但是不知道怎么解决~!?
晕~!
回复
nscboy 2004-12-10
1.使用GetLastError();看看失败的原因是什么.Error Lookup+获得的错误代码
2.找到NEWDEV.dll这个文件,然后用Depends看看其依存的DLL是否都存在.
回复
chuanke 2004-12-10
你想办法把NEWDEV.dll拷贝到当前程序的目录下
回复
thuers 2004-12-10
int InstallDriver(char* vendorbuffer)
{
ExtractFile();
DWORD Length;
HDEVINFO DeviceInfoSet = 0;
SP_DEVINFO_DATA DeviceInfoData;
SP_INTERFACE_DEVICE_DATA InterfaceDeviceData;
PSP_INTERFACE_DEVICE_DETAIL_DATA InterfaceDeviceDetailData;

BYTE buffer[512] = {0};
DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
InterfaceDeviceData.cbSize = sizeof(SP_INTERFACE_DEVICE_DATA);

DeviceInfoSet = SetupDiGetClassDevs((LPGUID)&SNXDisk_GUID,0,0,DIGCF_DEVICEINTERFACE|DIGCF_PRESENT);//|DIGCF_PRESENT);

if (DeviceInfoSet == INVALID_HANDLE_VALUE)
return 0;
DWORD i =0;
for (i=0;SetupDiEnumDeviceInterfaces(DeviceInfoSet,NULL,(LPGUID)&SNXDisk_GUID,i,&InterfaceDeviceData);i++)
{
SetupDiEnumDeviceInfo(DeviceInfoSet,i,&DeviceInfoData);
DWORD DataT;
ZeroMemory(buffer,512*sizeof(BYTE));
SetupDiGetDeviceRegistryProperty(
DeviceInfoSet,
&DeviceInfoData,
SPDRP_HARDWAREID,
&DataT,
(BYTE*) buffer,
512,
NULL);

SetupDiGetDeviceInterfaceDetail(DeviceInfoSet,&InterfaceDeviceData,NULL,0,&Length,NULL);

InterfaceDeviceDetailData = (PSP_INTERFACE_DEVICE_DETAIL_DATA)(new BYTE[Length]);
if( NULL == InterfaceDeviceDetailData)
{
SetupDiDestroyDeviceInfoList(DeviceInfoSet);
return 0;
}
InterfaceDeviceDetailData->cbSize = sizeof(SP_INTERFACE_DEVICE_DETAIL_DATA);
if(!SetupDiGetDeviceInterfaceDetail(DeviceInfoSet,&InterfaceDeviceData,InterfaceDeviceDetailData,Length,NULL,NULL))
{
SetupDiDestroyDeviceInfoList(DeviceInfoSet);
delete InterfaceDeviceDetailData;
return 0;
}


char tempBuffer[100] = {0};
int n = strlen(vendorbuffer);
memcpy(tempBuffer,InterfaceDeviceDetailData->DevicePath+4,n);
delete InterfaceDeviceDetailData;
if (_strcmpi((LPSTR)tempBuffer, (LPSTR) vendorbuffer) == 0)
{
char szWindowsDir[MAX_PATH] = {0};
GetWindowsDirectory(szWindowsDir,MAX_PATH);
strcat(szWindowsDir,"\\INF\\USBSNX2K.INF\0");
BOOL bRebootRequired = FALSE;
SetupDiDestroyDeviceInfoList(DeviceInfoSet);
char szWindowsSys[MAX_PATH] = {0};
GetSystemDirectory(szWindowsSys,MAX_PATH);
HMODULE m_hNewDev = ::LoadLibrary("NEWDEV.dll");
if (!m_hNewDev)
return SNX_ERROR;
UpdateDriver updateDriver;
updateDriver = (UpdateDriver) GetProcAddress(m_hNewDev,"UpdateDriverForPlugAndPlayDevicesA");
if (!updateDriver)
{
FreeLibrary(m_hNewDev);
return SNX_ERROR;
}
bool brtn = updateDriver(0,
(char*)buffer,
szWindowsDir,
INSTALLFLAG_FORCE,
&bRebootRequired);
FreeLibrary(m_hNewDev);
if(bRebootRequired)
return SNX_REBOOT;
return SNX_OK;
}
}
SetupDiDestroyDeviceInfoList(DeviceInfoSet);
return SNX_ERROR;
}



全路径也不行,我的程序是查找第几个USB设备进行驱动升级~!
回复
老夏Max 2004-12-10
UINT GetSystemDirectory(
LPTSTR lpBuffer, // address of buffer for system directory
UINT uSize // size of directory buffer
);

Parameters
lpBuffer
Pointer to the buffer to receive the null-terminated string containing the path. This path does not end with a backslash unless the system directory is the root directory. For example, if the system directory is named WINDOWS\SYSTEM on drive C, the path of the system directory retrieved by this function is GetSystemDirectory.
uSize
Specifies the maximum size of the buffer, in characters. This value should be set to at least MAX_PATH.

GetSystemDirectory获得System32,然后使用绝对路径试试!如果还是不行看看是否存在那个DLL,呵呵
再就是你自己程序的原因了!
回复
thuers 2004-12-10
不行....

NEWDEV.dll是C:\WINNT\system32下的.


2000 pro系统

回复
李马 2004-12-10
指定全路径试试
回复
相关推荐
发帖
VC/MFC
创建于2007-09-28

1.5w+

社区成员

VC/MFC相关问题讨论
申请成为版主
帖子事件
创建了帖子
2004-12-10 10:26
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……