Как сделать dll из приложения C ++ Console, которое можно использовать в приложении C #? LNK2019 Win32 DLL

Я хотел бы сделать DLL с функцией WS-Discovery.
Мой шаблон — это пример проекта Microsoft.
https://code.msdn.microsoft.com/windowsapps/WS-Discovery-SDK-Sample-8138b0d1/view/SourceCode
Внутри решения есть 3 проекта (Клиент, Общий и Сервис)
Я могу скомпилировать и запустить их все, и они работают нормально.

Я запускаю сервер с этими параметрами (я добавил пробел после http&HTTPS):
WSDiscoveryService.exe / a http: //192.168.2.53/onvif/device_service / s 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 Project, Application Type DLL)
Я добавил файлы Common.h и Common.cpp из общего проекта и 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, указанный в функции «long __cdecl GetWideStringHostName (wchar_t * *)» (? GetWideStringHostName @@ YAJPAPA_W @ Z) ServiceDll C: \ test \ C ++ \ ServiceDll \ Common.obj 1

Код серьезности Описание Состояние подавления строки файла проекта
Ошибка LNK2001: неразрешенный внешний символ _WSDAllocateLinkedMemory @ 8 ServiceDll C: \ test \ C ++ \ ServiceDll \ TargetService.obj 1

Код серьезности Описание Состояние подавления строки файла проекта
Ошибка LNK2019: неразрешенный внешний символ __imp__UuidCreate @ 4, на который ссылается функция «long __cdecl _GenerateEndpointReference (wchar_t * *)» (? _GenerateEndpointReference @@ YAJPAPA_W @ Z) ServiceDll C: \ test \ C ++ \ ServiceDll \ TargejSer.

Код серьезности Описание Состояние подавления строки файла проекта
Ошибка LNK1120 8 неразрешенных внешних файлов ServiceDll C: \ test \ C ++ \ Debug \ ServiceDll.dll 1

0

Решение

добавлять Ws2_32.lib;Wsdapi.lib;Rpcrt4.lib в ваши связанные библиотеки.

-1

Другие решения

Других решений пока нет …

По вопросам рекламы [email protected]