#include <stdio.h>
#include <shlobj.h>
#include <windows.h>
#include <atlbase.h>
#include <Shobjidl.h>
#include "pluginapi.h"
#pragma comment(lib,"nsis/pluginapi.lib")
#pragma comment(linker, "/NODEFAULTLIB:libc.lib")
wchar_t* AnsiToUnicode(const char* szStr)
{
int nLen = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, szStr, -1, NULL, 0);
if (nLen == 0)
{
return NULL;
}
wchar_t* pResult = new wchar_t[nLen];
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, szStr, -1, pResult, nLen);
return pResult;
}
//将宽字节wchar_t*转化为单字节char*
inline char* UnicodeToAnsi(const wchar_t* szStr)
{
int nLen = WideCharToMultiByte(CP_ACP, 0, szStr, -1, NULL, 0, NULL, NULL);
if (nLen == 0)
{
return NULL;
}
char* pResult = new char[nLen];
WideCharToMultiByte(CP_ACP, 0, szStr, -1, pResult, nLen, NULL, NULL);
return pResult;
}
extern HWND g_hwndParent;
extern "C" {
void __declspec(dllexport) editDir(HWND h, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra)
{
g_hwndParent = h;
wchar_t path1[200] = { 0 };
wsprintf(path1, L"hwnd=%d", g_hwndParent);
OutputDebugStringA("che");
OutputDebugStringW(path1);
EXDLL_INIT();
char indir[200] = {};
char outdir[200] = {};
popstring(indir);
FILEOPENDIALOGOPTIONS dwFlags;
IFileDialog *pfd = NULL;
IShellItem *ppsi = NULL;
LPWSTR filePath;
HRESULT hr = CoCreateInstance(CLSID_FileOpenDialog,
NULL,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&pfd));
if (SUCCEEDED(hr))
{
OutputDebugStringA("SUCCEEDED");
hr = pfd->GetOptions(&dwFlags);
hr = pfd->SetOptions(dwFlags | FOS_PICKFOLDERS);
//IFileDialog::Show();
//pfd->SetDefaultFolder(ppsi);
//PCWSTR path1 =;
/*wchar_t path1[200] = { 0 };
wsprintf(path1,L"%s",indir);*/
OutputDebugStringA(indir);
wchar_t *path1 = AnsiToUnicode(indir);
OutputDebugStringW(path1);
// {0E105A98-E4DD-42F2-B961-D2CF11070AF5}
static const GUID iid1 =
{ 0xe105a98, 0xe4dd, 0x42f2,{ 0xb9, 0x61, 0xd2, 0xcf, 0x11, 0x7, 0xa, 0xf5 } };
//SHCreateItemFromParsingName(path1, NULL, iid1, NULL);
CComPtr<IShellItem> shellItem;
hr = ::SHCreateItemFromParsingName(path1, 0, IID_IShellItem, reinterpret_cast<void**>(&shellItem));
pfd->SetFolder(shellItem);
pfd->SetDefaultFolder(ppsi);
pfd->Show(h);
pfd->GetResult(&ppsi);
if (ppsi)
{
// pfd->GetFolder(&ppsi);
OutputDebugStringA("ppsi");
ppsi->GetDisplayName(SIGDN_FILESYSPATH, &filePath);
OutputDebugStringW(filePath);
//char out[200] = { 0 };
char* out = UnicodeToAnsi(filePath);
//sprintf(out,"%s", filePath);
OutputDebugStringA(out);
pushstring(out);
}
else
{
return;
}
}
pfd->Release();
ppsi->Release();
}
void __declspec(dllexport) bindcallback(HWND h, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra)
{
g_hwndParent = h;
EXDLL_INIT();
char p1[20] = { 0 };
char p2[20] = { 0 };
if (stacktop != NULL)
{
int iFunc = 0;
if (*stacktop != NULL)
{
popstring(p1);
OutputDebugStringA("1");
OutputDebugStringA(p1);
}
if (strcmp(p1, "test1") == 0)
{
OutputDebugStringA("2");
OutputDebugStringA("p1==test1");
if (*stacktop != NULL)
{
OutputDebugStringA("3");
popstring(p2);
OutputDebugStringA(p2);
iFunc = strtoul(p2,0,0);
if (iFunc > 0)
{
OutputDebugStringA("4");
extra->ExecuteCodeSegment(iFunc-1, g_hwndParent);
}
}
}
else
{
OutputDebugStringA(p1);
OutputDebugStringA("p1!=test1");
}
}
}
}