如何从C++控制台应用程序中使用shell32.dll
How to use shell32.dll from C++ console application
我需要做的是获得ApplicationData
路径,我在谷歌上发现有一个叫做的函数
HRESULT SHGetFolderPath(
__in HWND hwndOwner,
__in int nFolder,
__in HANDLE hToken,
__in DWORD dwFlags,
__out LPTSTR pszPath
);
但它存在于shell32.dll中在C#中,我会做一些类似的事情
[DllImport]
static extern HRESULT SHGetFolderPath() and so on.
我需要在C++控制台应用程序中做些什么才能调用这个API?也许,我可以使用LoadLibrary()
?但正确的方法是什么?
我可以以某种方式静态链接这个dll作为我的exe的一部分吗?我正在使用Visual Studio 2010。
您需要#include shlobj.h并链接到shell32.lib
#include "stdafx.h"
#include <windows.h>
#include <shlobj.h>
#include <assert.h>
#pragma comment(lib, "shell32.lib")
int _tmain(int argc, _TCHAR* argv[])
{
TCHAR path[MAX_PATH];
HRESULT hr = SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, path);
assert(SUCCEEDED(hr));
// etc..
return 0;
}
#pragma注释负责将其告知链接器。
#include <Shlobj.h>
和#pragma comment(lib,"Shell32.lib")
应该可以工作。
相关文章:
- 挂起和取消挂起一个文件DLL
- std::threads可以从Windows DLL中的全局变量创建/销毁吗?
- 导入库可以跨dll版本工作吗
- 从C++dll访问C#中的一行主要参数
- 链接到自行创建的dll失败
- 为什么使用 P/Invoke 调用 dll 时,某些计算机中的 LoadLibrary 失败?
- 在调用FreeLibrary后,释放动态链接到具有相同版本的CRT堆的DLL的内存
- 如何指定我希望我的LIB链接到的DLL文件?-Visual Studio 2019
- 如何将图像传输到c++(dll)中的缓冲区,然后在c#的缓冲区中读/写
- C++:将外部库链接到dll库
- 在 Windows 上,是否可以让 dll 在不使用 PATH 环境变量的情况下在另一个文件夹中查找依赖项?
- 不同的Visual Studio版本中缺少.dll
- 从DLL中删除类的实例
- 如何包装第三方DLL在R中使用
- 使用c#访问c++dll中带有char*参数的函数时发生AccessViolationException
- 系统.将数组移交给c#中动态加载的c++DLL时发生AccessViolationException
- DeleteFile (kernel32.dll) vs DeleteItem (shell32.dll)
- 如何从C++控制台应用程序中使用shell32.dll
- 我如何导入Shell32.dll的表地址(在explorer.exe中)
- 使用 GUIDFromString 要求(包括 Shell32.dll:我该怎么做