moiit
5th March 2012, 08:32
My Qt app needs to invoke a function with arguments from my owned dll, which was created with VS2010.
It runs as expected if the imported function without any argument.
But with arguments it will crash, although there is no problem when compiling.
Any advise will be helpful!
Thanks.
//.pro
LIBS += -L ./ -lop
//op.h
#ifndef OP_H
#define OP_H
#include <string>
extern "C" __declspec(dllexport) void excute(std::wstring url);
#endif // OP_H
//invoke code
std::wstring url=qstr_url.toStdWString();
excute(url);
//dll in vs2010
// op.cpp
#include "stdafx.h"
extern "C" __declspec(dllexport) void excute(std::wstring url )
{
STARTUPINFO start_info;
PROCESS_INFORMATION proc_info;
::ZeroMemory(&start_info, sizeof(start_info));
start_info.cb = sizeof(start_info);
::ZeroMemory(&proc_info, sizeof(proc_info));
std::wstring browser = L"C:/Program Files/Internet Explorer/iexplore.exe";
//std::wstring url = L"http://google.com";
std::wstring command = browser + L" " + url;
LPWSTR command_line = new WCHAR[command.size() + 1];
wcscpy_s(command_line, command.size() + 1, command.c_str());
command_line[command.size()] = L'\0';
::CreateProcess(NULL, command_line, NULL, NULL, FALSE, 0, NULL, NULL, &start_info, &proc_info);
if (proc_info.hThread != NULL) {
::CloseHandle(proc_info.hThread);
}
if (proc_info.hProcess != NULL) {
::CloseHandle(proc_info.hProcess);
}
It runs as expected if the imported function without any argument.
But with arguments it will crash, although there is no problem when compiling.
Any advise will be helpful!
Thanks.
//.pro
LIBS += -L ./ -lop
//op.h
#ifndef OP_H
#define OP_H
#include <string>
extern "C" __declspec(dllexport) void excute(std::wstring url);
#endif // OP_H
//invoke code
std::wstring url=qstr_url.toStdWString();
excute(url);
//dll in vs2010
// op.cpp
#include "stdafx.h"
extern "C" __declspec(dllexport) void excute(std::wstring url )
{
STARTUPINFO start_info;
PROCESS_INFORMATION proc_info;
::ZeroMemory(&start_info, sizeof(start_info));
start_info.cb = sizeof(start_info);
::ZeroMemory(&proc_info, sizeof(proc_info));
std::wstring browser = L"C:/Program Files/Internet Explorer/iexplore.exe";
//std::wstring url = L"http://google.com";
std::wstring command = browser + L" " + url;
LPWSTR command_line = new WCHAR[command.size() + 1];
wcscpy_s(command_line, command.size() + 1, command.c_str());
command_line[command.size()] = L'\0';
::CreateProcess(NULL, command_line, NULL, NULL, FALSE, 0, NULL, NULL, &start_info, &proc_info);
if (proc_info.hThread != NULL) {
::CloseHandle(proc_info.hThread);
}
if (proc_info.hProcess != NULL) {
::CloseHandle(proc_info.hProcess);
}