1

嘿,我希望有人能告诉我要解决这个问题,我一直从 Visual Studio 收到以下文件的错误 2019。现在大部分功能已被删除,所以请原谅空变量等。

错误错误 LNK2019:函数 _wmain c:\Users\K\documents\visual 中引用的未解析的外部符号“void * __cdecl OpenOneDevice(void *,struct _SP_DEVICE_INTERFACE_DATA *,char *)”(?OpenOneDevice@@YAPAXPAXPAU_SP_DEVICE_INTERFACE_DATA@@PAD@Z)工作室 2010\Projects\test2\test2\test2.obj test2

#include "stdafx.h"
#include <windows.h>
#include <setupapi.h>

SP_DEVICE_INTERFACE_DATA deviceInfoData;
HDEVINFO hwDeviceInfo;
HANDLE hOut;
char *devName;
//
HANDLE OpenOneDevice(IN HDEVINFO hwDeviceInfo,IN PSP_DEVICE_INTERFACE_DATA DeviceInfoData,IN char *devName);
//
HANDLE OpenOneDevice(IN HDEVINFO HardwareDeviceInfo,IN PSP_DEVICE_INTERFACE_DATA DeviceInfoData,IN char *devName) {
    PSP_DEVICE_INTERFACE_DETAIL_DATA functionClassDeviceData = NULL;
    ULONG predictedLength = 0, requiredLength = 0;
    HANDLE hOut = INVALID_HANDLE_VALUE;

    SetupDiGetDeviceInterfaceDetail(HardwareDeviceInfo, DeviceInfoData, NULL, 0, &requiredLength, NULL);

    predictedLength = requiredLength;

    functionClassDeviceData = (PSP_DEVICE_INTERFACE_DETAIL_DATA)malloc(predictedLength);
    if(NULL == functionClassDeviceData) {
        return hOut;
    }
    functionClassDeviceData->cbSize = sizeof (SP_DEVICE_INTERFACE_DETAIL_DATA);

    if (!SetupDiGetDeviceInterfaceDetail(HardwareDeviceInfo, DeviceInfoData, functionClassDeviceData,
        predictedLength, &requiredLength, NULL)) {
        free( functionClassDeviceData );
        return hOut;
    }

    //strcpy(devName,functionClassDeviceData->DevicePath) ;

    hOut = CreateFile(functionClassDeviceData->DevicePath, GENERIC_READ | GENERIC_WRITE,
        FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);

    free(functionClassDeviceData);
    return hOut;
}


// 
int _tmain(int argc, _TCHAR* argv[])
{



    hOut = OpenOneDevice (hwDeviceInfo, &deviceInfoData, devName);
    if(hOut != INVALID_HANDLE_VALUE) 
        {
            // error report
        }
    return 0;
}

几个小时让我发疯。任何帮助表示赞赏。

感谢克里斯解决:-)

添加#pragma 注释(lib,“Setupapi.lib”)

谢谢

4

0 回答 0