2017-05-18 93 views
0

我想用WS-Discovery函數製作dll。 我的模板是這個Microsoft示例項目。 https://code.msdn.microsoft.com/windowsapps/WS-Discovery-SDK-Sample-8138b0d1/view/SourceCode 裏面的解決方案有3個項目(客戶端,通用和服務) 我可以編譯和運行所有這些,他們工作正常。如何從C++控制檯應用程序,可用於C#應用程序的DLL? LNK2019 Win32 DLL

我運行服務器與這些參數(I之後HTTP & HTTPS額外的空間): WSDiscoveryService.exe /一個http://192.168.2.53/onvif/device_service /秒的https://www.onvif.org/ver10 /device/wsdl/devicemgmt.wsdl https://www.onvif.org/ver20/ptz/wsdl/ptz.wsdl https://www.onvif.org/ver10/media/wsdl/media.wsdl https:// www.onvif.org/ver10/events/wsdl/event.wsdl

一切都很好,直到現在。

現在我已經將新項目添加到解決方案ServiceDll(Win32項目,應用程序類型DLL) 我已經從Common項目中添加Common.h和Common.cpp文件,從Service項目中添加了TargetService.h和TargetService.cpp文件。 後來我加入這個代碼ServiceDll.cpp

// ServiceDll.cpp : Defines the exported functions for the DLL application. 

#include "stdafx.h" 
#include <windows.h> 
#include <stdlib.h> 
#include <strsafe.h> 
#include <string.h> 
#include <stdio.h> 
#include <conio.h> 
#include <wsdapi.h> 
#include "Common.h" 
#include "TargetService.h" 

#if !defined(WS_DISCOVERY) 

CTargetService *service = NULL; 

// Exspose 5 methods to outside. (prototypes) 

// create service and start lissen for probe messages. 
// if return value is 1 service is created and active. 
// if return value is 0 something is wrong. 
extern "C" __declspec(dllexport) int __cdecl WSDiscoveryCreate(LPWSTR endpointReference,WSD_URI_LIST *scopes); 

// get Endpoint reference of service 
// if return string is 0 then service is not running. 
extern "C" __declspec(dllexport) LPCWSTR __cdecl WSDiscoveryGetEndpointReference(); 

// send hello message 
// if return value is 1 helo message was sended. 
// if return value is 0 something is wrong. 
extern "C" __declspec(dllexport) int __cdecl WSDiscoveryHello(); 

// send bye message, this don't stop the service. 
// if return value is 1 bye message was sended. 
// if return value is 0 something is wrong. 
extern "C" __declspec(dllexport) int __cdecl WSDiscoveryBye(); 

// stop service and dispose used objects 
// if return value is 1 service was disposed or service was not created in first place. 
// if return value is 0 something is wrong. 
extern "C" __declspec(dllexport) int __cdecl WSDiscoveryDispose(); 


// (inplementation) 
extern "C" __declspec(dllexport) int __cdecl WSDiscoveryCreate(LPWSTR endpointReference,WSD_URI_LIST *scopes) 
{ 
HRESULT hr = S_OK; 
hr = CreateTargetService(endpointReference, scopes, &service); 
if (hr == S_OK) 
{ 
    return 1; 
} 
else 
{ 
    return 0; 
} 
} 

extern "C" __declspec(dllexport) LPCWSTR __cdecl WSDiscoveryGetEndpointReference() 
{ 
LPCWSTR temp = L"0"; 
HRESULT hr = S_FALSE; 
if (NULL != service) 
{ 
    hr = service->GetEndpointReference(&temp); 
    if (hr == S_OK) 
    { 
     return temp; 
    } 
} 
return temp; 
} 

extern "C" __declspec(dllexport) int __cdecl WSDiscoveryHello() 
{ 
if (NULL != service) 
{ 
    HRESULT hr = service->SendHelloMessage(); 
    if (hr == S_OK) 
    { 
     return 1; 
    } 
} 
return 0; 
} 

extern "C" __declspec(dllexport) int __cdecl WSDiscoveryBye() 
{ 
if (NULL != service) 
{ 
    HRESULT hr = service->SendByeMessage(); 
    if (hr == S_OK) 
    { 
     return 1; 
    } 
} 
return 0; 
} 

extern "C" __declspec(dllexport) int __cdecl WSDiscoveryDispose() 
{ 
if (NULL != service) 
{ 
    HRESULT hr = service->Terminate(); 
    if (hr == S_OK) 
    { 
     if (NULL != service) 
     { 
      service->Release(); 
      service = NULL; 
     } 
     return 1; 
    } 
    else 
    { 
     return 0; 
    } 
} 
else 
{ 
    // service was not created. 
    return 1; 
} 
} 

#endif /* !defined(WS_DISCOVERY) */ 

現在,我嘗試建立這個DLL,我得到11個錯誤: 8X LNK2019 2X LNK2001 1X LNK1120

嚴重性代碼說明項目文件禁止線狀態 錯誤LNK2019解析外部符號__imp__gethostname @ 8函數引用 「長__cdecl GetWideStringHostName(wchar_t的* *)」(GetWideStringHostName @@ YAJPAPA_W @ Z?)ServiceDll C:\測試\ C++ \ ServiceDll \ Common.obj 1

嚴重性代碼描述項目文件行抑制狀態 錯誤LNK2001解析外部符號_WSDAllocateLinkedMemory @ 8 ServiceDll C:\測試\ C++ \ ServiceDll \ TargetService.obj 1

嚴重性代碼描述項目文件行抑制狀態 錯誤LNK2019解析的外部符號__imp__UuidCreate @在功能標記爲4 「長__cdecl _GenerateEndpointReference(wchar_t的* *)」(_GenerateEndpointReference @@ YAJPAPA_W @ Z?)ServiceDll C:\測試\ C++ \ ServiceDll \ TargetService.obj 1

嚴重性代碼描述項目文件行抑制狀態 錯誤LNK1120 8個未解析的外部ServiceDll C:\ test \ C++ \ Debug \ ServiceDll.dll 1

+0

開始小而簡單,並從那裏建立;詳情請參見[mcve]。 –

+0

比這更簡單嗎? 1.下載Microsoft解決方案示例並編譯它。 2.將新項目添加到MS解決方案(Win32 DLL)。 3.提供粘貼代碼並按編譯。 在不到5分鐘內,您可以複製鏈接器錯誤。 – user1513890

回答

-1

Ws2_32.lib;Wsdapi.lib;Rpcrt4.lib添加到您的鏈接庫。

相關問題