c++ Cli WebClient不能在dll中工作
C++ Cli WebClient not working in a dll
我正在尝试使用c++/Cli中的WebClient从web地址下载字符串。但是,在将dll注入本机进程后,它将失败。
这是我的代码:
#include <Windows.h>
using namespace System;
using namespace System::Net;
using namespace System::Windows;
using namespace System::Windows::Forms;
BOOL WINAPI DllMain(_In_ HINSTANCE hinstDLL,_In_ DWORD fdwReason,_In_ LPVOID lpvReserved)
{
if (fdwReason == DLL_PROCESS_ATTACH) {
System::Windows::Forms::MessageBox::Show("test");
WebClient web;
String^ Data = web.DownloadString("http://www.google.com");
System::Windows::Forms::MessageBox::Show(Data);
}
return TRUE;
}
在Data字符串初始化之前,它会正常工作,但由于某种原因,执行会停止。弹出窗口:显示("测试");虽然有用,但之后就没有了。是什么原因造成的呢?
原来你只需要链接你的托管/本地混合dll对winsock库(ws2_32.lib) &为下载创建一个单独的线程
相关文章:
- 导入库可以跨dll版本工作吗
- 名为DLL的C++windows服务程序工作不正常
- 从Excel VBA调用C++DLL只能从Visual Studio中的调试实例工作
- PlayFunction在DLL中不起作用,但在独立的exe中工作
- Windows API "CreateWindowEx" 在 Python (3.6.8) 64 位使用的 DLL 中工作吗?
- 如何将C++ dll 在 C# 窗口窗体应用程序下的工作线程中运行
- C++ Dll 无法在未安装 Visual Studio 的系统上工作
- DLL函数在VBA环境中不起作用,但在Excel VBA中工作
- 在dll中静态对象的破坏之前,要终止工作线程(但不是.exe)
- Dll进程挂钩不工作
- 运行在DLL中的工作线程在应用程序关闭时被终止,然后才能正常关闭它们
- 获取 dll include 以在 Visual Studio 中工作
- C++:无法使用 regsvr32 注册我的 DLL,但可以通过 IDE 工作
- C++Dll注入——Hello world Dll只有在注入到注入它的相同.exe中时才能工作
- 如何使 *.dll WinAmp 插件在朋友电脑上工作
- 为什么有些函数需要作为DLL文件注入才能工作
- 导入 DLL 的工作方式不同(VS2003 到 VS2010,多线程到多线程 DLL)
- 以下代码是如何工作的(从DLL加载动态类)
- C# IteropServices with C++ dll - 在excel中工作
- DLL 导致"Microsoft Excel has stopped working"但它在 Win32 控制台应用中工作正常