Invoking dll function with argument crashed
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
//op.h
Code:
#ifndef OP_H
#define OP_H
#include <string>
extern "C" __declspec(dllexport) void excute(std::wstring url);
#endif // OP_H
//invoke code
Code:
std::wstring url=qstr_url.toStdWString();
excute(url);
//dll in vs2010
// op.cpp
Code:
#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);
}
Re: Invoking dll function with argument crashed
Run it in a debugger, and step through, and see on which line it crashes.
Then we can start looking with some idea on what to look for.
It doesn't sound like a problem with the lib, but more like a problem in the code in self, in execute() - probably a pointer issue or similar.
Re: Invoking dll function with argument crashed
thanks for advise!
debug result point to the invoking code line:
excute(url);
but there is only this line doing the invoking from dll.
i don't know what's wrong with it.
i use the implicit invocation in qt codes.
i tried explicit invoking but the result is the same.
Re: Invoking dll function with argument crashed
Add a check to make sure the url parameter is not null - before calling execute() - in in execute it self - it should be able to exit gracefully on null string url.
Re: Invoking dll function with argument crashed
thanks for advise!
i added one line like you said:
Code:
if(url.length()!=0)
excute(url);
but it stiil crashed.
Re: Invoking dll function with argument crashed
Single step your code inside excute(), it's failing among that non-Qt code somewhere.
Does ieexplore.exe exist at that path? The space embedded in the path to iexplore.exe is possibly causing issues: see the CreateProcess docs.
Or... use Qt because QDesktopServices::openUrl() is a much easier way to launch the system default browser.
Re: Invoking dll function with argument crashed
yes, maybe merging browser path and link is the issue. so i modified the codes:
Code:
#include "stdafx.h"
extern "C" __declspec(dllexport) void excute() //removed arguments to open google page, but it opened a blank page
{
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));
LPCTSTR browser = L"G:/Program Files/Internet Explorer/iexplore.exe";
LPTSTR command_line = L"http://google.com";
::CreateProcess(browser, 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);
}
this time, it did not crash, but ie opened with a blank page, not google.
i must be crazy...
Re: Invoking dll function with argument crashed
Why don't you do what we suggested to you?
Step through exectue() - and follow your url variable and all other values - and you will see exactly what and when is going wrong.
Re: Invoking dll function with argument crashed
sorry but i did the debug and it pointed to that the issue code line is "excute(url);" , and the url is right.
so what i think is the dll has some wrong codes.
in post #7, i modified some codes, it did not crash now, but it opened a blankpage instead of the assigned url.
Re: Invoking dll function with argument crashed
maybe you don't understand what is meant:
by stepping through, you step one line at a time during execution in the debugger - IN your execute() function.
This way you can examine all the values of your variables, and see which ones do not match what you expect.
You might want to escape the slashes in the path to iexploere.
Re: Invoking dll function with argument crashed
thanks for advise!
do you mean running vs2010's debugger to check the dll function?
then i will do.
Re: Invoking dll function with argument crashed
Yes - what ever debugger you are using will be fine.
Re: Invoking dll function with argument crashed
But remember that you must build a DEBUG version of your DLL in order to step into its execute() method and debug it. You can't link to a release version of the DLL and debug it.
Re: Invoking dll function with argument crashed
thanks for all you guys's help!
i must learn more, more...