Я построил DLL, названный «dllhttprest2.dll», используя Cpprest SDK. Код отправляет запрос на поиск в Bing. Параметры поиска - «cpprestsdk» и «github». После создания DLL я скопировал его в тот же каталог, что и мое тестовое приложение. Тестовое приложение вызывает функцию LoadLibrary (), получает адрес PROC Function, а затем вызывает функцию. В тестовом приложении, когда я загружаю DLL, используя функцию LoadLibrary, я получаю последнюю ошибку = 126. Код работает нормально, когда он построен в качестве приложения консоли. < /P>
// dllmain.cpp : Defines the entry point for the DLL application.
#include "pch.h"
#include
#include
#include
std::string test = "not Loaded";
using namespace utility;
using namespace web;
using namespace web::http;
using namespace web::http::client;
using namespace concurrency::streams;
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;
}
extern "C" __declspec(dllexport) int getBingResponse()
{
auto fileStream = std::make_shared();
// Open stream to output file.
pplx::task requestTask = fstream::open_ostream(U("results.html")).then([=](ostream outFile)
{
*fileStream = outFile;
// Create http_client to send the request.
http_client client(U("http://www.bing.com/"));
// Build request URI and start the request.
uri_builder builder(U("/search"));
builder.append_query(U("q"), U("cpprestsdk github"));
return client.request(methods::GET, builder.to_string());
})
// Handle response headers arriving.
.then([=](http_response response)
{
printf("Received response status code:%u\n", response.status_code());
// Write response body into the file.
return response.body().read_to_end(fileStream->streambuf());
})
// Close the file stream.
.then([=](size_t)
{
return fileStream->close();
});
// Wait for all the outstanding I/O to complete and handle any exceptions
try
{
requestTask.wait();
}
catch (const std::exception& e)
{
printf("Error exception:%s\n", e.what());
}
return 0;
}
< /code>
Код тестового приложения здесь: < /p>
#include
#include
typedef int(*GetBingResponseFunc)();
void PrintErrorMessage(DWORD errorCode) {
LPVOID lpMsgBuf;
DWORD bufLen = FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
errorCode,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)&lpMsgBuf,
0, NULL);
if (bufLen) {
LPCSTR lpMsgStr = (LPCSTR)lpMsgBuf;
std::cerr p;
GetBingResponseFunc getBingResponse = (GetBingResponseFunc)GetProcAddress(hDll, "getBingResponse");
if (getBingResponse == NULL)
{
DWORD errorCode = GetLastError();
std::cerr
Подробнее здесь: https://stackoverflow.com/questions/794 ... pprest-sdk
Как загрузить DLL, построенный с помощью CPPREST SDK ⇐ C++
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Как добавить пункт за заказ по запросу codeigniter, построенный с помощью get_where ()
Anonymous » » в форуме Php - 0 Ответы
- 2 Просмотры
-
Последнее сообщение Anonymous
-