通过进程link路径(快捷方式路径)得到进程完整路径

程序中遇到的问题及解决方法:

#error WINDOWS.H already included. MFC apps must not #include <windows.h>
解决方法:把#include "afxtempl.h"放到程序所包含的所有头文件的前面

vs编译时出现大量ws2def.h的错误的解决方法
解决方法:(注意:顺序必须是这样)
#include "Winsock2.h"
#include "windows.h"

Building MFC application with /MD[d] (CRT dll version)requires MFC shared dll version
解决方法:在 项目/属性/常规/use of MFC 选项中选择 Use MFC in a Shared DLL

源码:

// InkNameToFullPathName.cpp : 定义控制台应用程序的入口点。
// #include "stdafx.h"
#include "afxtempl.h"
#include "Winsock2.h"
#include <windows.h>
#include <afxctl.h>
#include <string.h> using namespace std;
BOOL ExpandShortcut(PWCHAR outFile, PWCHAR inFile); int main()
{ //WCHAR FileFullPathData[MAX_PATH] = { 0 };
WCHAR* FileFullPathData = L"C:\\Users\\Public\\Desktop\\腾讯QQ.lnk" ;
WCHAR FileRealFullPathData[MAX_PATH] = { 0 };
if (wcsstr(FileFullPathData, L".lnk") != NULL)
{
if (ExpandShortcut(FileRealFullPathData, FileFullPathData))
{
} }
return 0;
} BOOL ExpandShortcut(PWCHAR outFile, PWCHAR inFile)
{
IShellLink* ISLink;
HRESULT hres;
WIN32_FIND_DATA FindDATA;
CoInitialize(NULL);
hres = ::CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
IID_IShellLink, (LPVOID*)&ISLink);
if (SUCCEEDED(hres))
{
IPersistFile* IPFile;
hres = ISLink->QueryInterface(IID_IPersistFile, (LPVOID*)&IPFile);
if (SUCCEEDED(hres))
{
hres = IPFile->Load(inFile, STGM_READ);
if (SUCCEEDED(hres))
HRESULT hres = ISLink->GetPath(outFile, MAX_PATH, &FindDATA, SLGP_UNCPRIORITY);
printf("%ls\n", outFile);
if (SUCCEEDED(hres))
return TRUE;
} ISLink->Release();
} return FALSE;
}

  

上一篇:day 1——字典树练习


下一篇:如何给TableLayout加边框