Sign in to follow this  
Followers 0
E1M1

what can possibly cause @error = 1 with dllcall?

16 posts in this topic

Func OpenProcessByWindow($hWnd)
    $call = DllCall("file.dll", "handle:cdecl", "openSecureProcess", "int", WinGetProcess($hWnd), "dword", 0x001F0FFF)
    MsgBox(0,"error",@error)
    If Not @error Then
        Return $call[0]
    Else
        Return False
    EndIf
EndFunc   ;==> OpenProcessByWindow

Dll src

// formulas.cpp : Defines the exported functions for the DLL application.
//

#include "stdafx.h"
#include "windows.h"
#define WIN32_LEAN_AND_MEAN
#include <AccCtrl.h>
#include <Aclapi.h>


#define DLL extern "C" __declspec(dllexport)

DLL HANDLE openSecureProcess(int wndpid,DWORD rights)
{
      int pid = wndpid;
      HWND window;
      HANDLE process;
      PACL dacl;
      PSECURITY_DESCRIPTOR secdesc;

     
      // Try to open the process with the requested rights.
      process = OpenProcess(rights, 0, pid);
      if(process != 0)
      {
         return process;
      }

      // Get the DACL of this process since we know we have
      // all rights in it. This really can't fail.
      if(GetSecurityInfo(GetCurrentProcess(),
                         SE_KERNEL_OBJECT,
                         DACL_SECURITY_INFORMATION,
                         0,
                         0,
                         &dacl,
                         0,
                         &secdesc) != ERROR_SUCCESS)
      {
         return 0;
      }
     
      // Open it with WRITE_DAC access so that we can write to the DACL.
      process = OpenProcess(WRITE_DAC, 0, pid);
      if(process == 0)
      {
         LocalFree(secdesc);
         return 0;
      }
     
      if(SetSecurityInfo(process,
                         SE_KERNEL_OBJECT,
                         DACL_SECURITY_INFORMATION |
                         UNPROTECTED_DACL_SECURITY_INFORMATION,
                         0,
                         0,
                         dacl,
                         0) != ERROR_SUCCESS)
      {
         LocalFree(secdesc);
         return 0;
      }
         
      // The DACL is overwritten with our own DACL. We
      // should be able to open it with the requested
      // privileges now.
      CloseHandle(process);
      LocalFree(secdesc);
      process = OpenProcess(rights, 0, pid);
      if(process == 0)
      {
         return 0;
      }

      return process;
}

I just need to know all possibilites. everything that could possibly cause @error 1.

thanks


edited

Share this post


Link to post
Share on other sites



$call = DllCall("file.dll", "handle:cdecl", "openSecureProcess", "int", WinGetProcess($hWnd), "dword", 0x001F0FFF)

// formulas.cpp : Defines the exported functions for the DLL application.
#define DLL extern "C" __declspec(dllexport)
DLL HANDLE openSecureProcess(int wndpid,DWORD rights)

I just need to know all possibilites. everything that could possibly cause @error 1.

Problem #1: __declspec(dllexport) <> __cdecl

Problem #2: AutoIt cannot use exports with dllexport calling convention. Define DLL as __stdcall and use DEF file to declare your exports.


UDFS & Apps:


DDEML.au3 - DDE Client + Server[*]
Localization.au3- localize your scripts[*]
TLI.au3 - type information on COM objects (TLBINF emulation)[*]
TLBAutoEnum.au3 - auto-import of COM constants (enums)[*]
AU3Automation - export AU3 scripts via COM interfaces
TypeLibInspector

- OleView was yesterday

Coder's last words before final release: WE APOLOGIZE FOR INCONVENIENCE 

Share this post


Link to post
Share on other sites

ok I replaced __declspec(dllexport) with __cdecl

Now i have.

#define DLL extern "C" __cdecl(dllexport)

but this one replacement caused 3 errors

1>c:\users\rain\documents\visual studio 2008\projects\formulas\formulas\formulas.cpp(13) : error C2059: syntax error : '('
1>c:\users\rain\documents\visual studio 2008\projects\formulas\formulas\formulas.cpp(14) : error C2143: syntax error : missing ';' before '{'
1>c:\users\rain\documents\visual studio 2008\projects\formulas\formulas\formulas.cpp(14) : error C2447: '{' : missing function header (old-style formal list?)
1>Build log was saved at "file://c:\Users\rain\Documents\Visual Studio 2008\Projects\formulas\formulas\Debug\BuildLog.htm"

Problem #2: AutoIt cannot use exports with dllexport calling convention. Define DLL as __stdcall and use DEF file to declare your exports.

Is this dllmain enough?

// dllmain.cpp : Defines the entry point for the DLL application.
#include "stdafx.h"

BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
                     )
{
    switch (ul_reason_for_call)
    {
    case DLL_PROCESS_ATTACH:
    case DLL_THREAD_ATTACH:
    case DLL_THREAD_DETACH:
    case DLL_PROCESS_DETACH:
        break;
    }
    return TRUE;
}

Sorry for silly questions, I am just not C++ expert yet.


edited

Share this post


Link to post
Share on other sites

What expert are you?

Use 32-bit AutoIt. You compiled 32-bit dll.

Problem #1: __declspec(dllexport) <> __cdecl

Problem #2: AutoIt cannot use exports with dllexport calling convention. Define DLL as __stdcall and use DEF file to declare your exports.

;)

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

ok I replaced __declspec(dllexport) with __cdecl

Now i have.

#define DLL extern "C" __cdecl(dllexport)

Nope, this is just wrong.

In your file.cpp:

#define DLL __cdecl
Add file.def to your VS project:

LIBRARY
EXPORTS
    openSecureProcess

Is this dllmain enough?

// dllmain.cpp : Defines the entry point for the DLL application.
#include "stdafx.h"
BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
                     )
{
    switch (ul_reason_for_call)
    {
    case DLL_PROCESS_ATTACH:
    case DLL_THREAD_ATTACH:
    case DLL_THREAD_DETACH:
    case DLL_PROCESS_DETACH:
        break;
    }
    return TRUE;
}

Returning TRUE will suffice, unless you need further module initialization/clean-up.

UDFS & Apps:


DDEML.au3 - DDE Client + Server[*]
Localization.au3- localize your scripts[*]
TLI.au3 - type information on COM objects (TLBINF emulation)[*]
TLBAutoEnum.au3 - auto-import of COM constants (enums)[*]
AU3Automation - export AU3 scripts via COM interfaces
TypeLibInspector

- OleView was yesterday

Coder's last words before final release: WE APOLOGIZE FOR INCONVENIENCE 

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

This created ecen more errors for some reason.

1>------ Build started: Project: formulas, Configuration: Debug Win32 ------
1>Compiling...
1>formulas.cpp
1>c:\users\rain\documents\visual studio 2008\projects\formulas\formulas\formulas.cpp(13) : error C2146: syntax error : missing ';' before identifier 'openSecureProcess'
1>c:\users\rain\documents\visual studio 2008\projects\formulas\formulas\formulas.cpp(13) : warning C4229: anachronism used : modifiers on data are ignored
1>c:\users\rain\documents\visual studio 2008\projects\formulas\formulas\formulas.cpp(13) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\rain\documents\visual studio 2008\projects\formulas\formulas\formulas.cpp(13) : error C2377: 'HANDLE' : redefinition; typedef cannot be overloaded with any other symbol
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winnt.h(402) : see declaration of 'HANDLE'
1>c:\users\rain\documents\visual studio 2008\projects\formulas\formulas\formulas.cpp(14) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\rain\documents\visual studio 2008\projects\formulas\formulas\formulas.cpp(17) : error C2146: syntax error : missing ';' before identifier 'process'
1>c:\users\rain\documents\visual studio 2008\projects\formulas\formulas\formulas.cpp(17) : error C2065: 'process' : undeclared identifier
1>c:\users\rain\documents\visual studio 2008\projects\formulas\formulas\formulas.cpp(23) : error C2065: 'process' : undeclared identifier
1>c:\users\rain\documents\visual studio 2008\projects\formulas\formulas\formulas.cpp(24) : error C2065: 'process' : undeclared identifier
1>c:\users\rain\documents\visual studio 2008\projects\formulas\formulas\formulas.cpp(26) : error C2065: 'process' : undeclared identifier
1>c:\users\rain\documents\visual studio 2008\projects\formulas\formulas\formulas.cpp(44) : error C2065: 'process' : undeclared identifier
1>c:\users\rain\documents\visual studio 2008\projects\formulas\formulas\formulas.cpp(45) : error C2065: 'process' : undeclared identifier
1>c:\users\rain\documents\visual studio 2008\projects\formulas\formulas\formulas.cpp(51) : error C2065: 'process' : undeclared identifier
1>c:\users\rain\documents\visual studio 2008\projects\formulas\formulas\formulas.cpp(67) : error C2065: 'process' : undeclared identifier
1>c:\users\rain\documents\visual studio 2008\projects\formulas\formulas\formulas.cpp(69) : error C2065: 'process' : undeclared identifier
1>c:\users\rain\documents\visual studio 2008\projects\formulas\formulas\formulas.cpp(70) : error C2065: 'process' : undeclared identifier
1>c:\users\rain\documents\visual studio 2008\projects\formulas\formulas\formulas.cpp(75) : error C2065: 'process' : undeclared identifier
1>Build log was saved at "file://c:\Users\rain\Documents\Visual Studio 2008\Projects\formulas\formulas\Debug\BuildLog.htm"
1>formulas - 16 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

My whole project is attached. I did every thing like you said. Hmm what could be wrong.

Edited by E1M1

edited

Share this post


Link to post
Share on other sites

What doudou is saying is misleading. Your original problem is not even related.

Run this:

ConsoleWrite(DllOpen("msvcr90d.dll")& @CRLF)

What you get?

It will show how dumb you are. Don't lie.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

E1M1, she's right - look at the Imports for your DLL. Use whatever Import viewer you like (I tend to use the one in my signature for some reason ;)). Your DLL relies on the presence of 'msvcr90d.dll', hence trancexx's code snippet.

Unfortunately, it looks like you aren't actually calling the Visual C++ library yourself - it all looks like indirect functions that are included as part of the compile process.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

What doudou is saying is misleading. Your original problem is not even related.

Run this:

ConsoleWrite(DllOpen("msvcr90d.dll")& @CRLF)

What you get?

It will show how dumb you are. Don't lie.

it gets me -1 but when i changed it to user32.dll I got 1

E1M1, she's right - look at the Imports for your DLL. Use whatever Import viewer you like (I tend to use the one in my signature for some reason ;)). Your DLL relies on the presence of 'msvcr90d.dll', hence trancexx's code snippet.

Unfortunately, it looks like you aren't actually calling the Visual C++ library yourself - it all looks like indirect functions that are included as part of the compile process.

I googled for one (i searched for "dll Import viewer" but all i found was some export viewers but not import), but didnt find. Dll viewer from yous signature http://www.autoitscript.com/forum/index.php?showtopic=99106 just deals with string like

local $sStructStr="Align 16;Short Albi;byte;hwnd;char;byte;short[2];dword;byte;short;byte;"& _
"int64;char[9];int64;byte;byte;ptr;char;double;short;wchar[3];byte;float;byte;uint_ptr;byte;" & _
"int;byte[13];word 2bytes;handle isptr;hwnd isalsoptr;boolean isbyte[2];bool isint;" & _
"dword_ptr;long_ptr;ulong_ptr;lparam;wparam;lresult"

but it doesn't view imports in my dll.

Edit1: Export viewer shows me:

Entrypoint Ord Name

1001113Bh 1 openSecureProcess

Edit2: finally found how to view imports.

Edited by E1M1

edited

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

it gets me -1 but when i changed it to user32.dll I got 1

After this post it's clear that explaining (to you) what fails in your example would be mission impossible. You simply wouldn't understand. Even though the plainness of the solution and the issue itself is too obvious.

Terrible.

Go read some books, something... anything. Then come back and you will have a big laugh at yourself. I promise.

Edited by trancexx

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

After this post it's clear that explaining (to you) what fails in your example would be mission impossible. You simply wouldn't understand. Even though the plainness of the solution and the issue itself is too obvious.

Terrible.

Go read some books, something... anything. Then come back and you will have a big laugh at yourself. I promise.

What do you mean by that? No one even didn't try to explain me what's wrong. well doudou tried and I did exactly what he said, it just didn't work. As I said before C is not my strong side. What's that point I didn't get? Could you make me clear one thing about my firs post? Which code is wrong? DLL's or AutoIt's?

it gets me -1 but when i changed it to user32.dll I got 1

How can this clearify wether I am dumb or not? You wanted return value of that function, I gave it you. Edited by E1M1

edited

Share this post


Link to post
Share on other sites

I googled for one (i searched for "dll Import viewer" but all i found was some export viewers but not import), but didnt find. Dll viewer from yous signature

This-> File + Process Imports/Exports Information is the Imports/Exports viewer I made.

Your DLL relies on 'msvcr90d.dll', thats why its in the Imports list. If it can't load all the DLL's and get function addresses for the functions in the Imports list, Windows will fail to initialize your DLL. However, even with msvcr90d.dll in the same folder as yours (I downloaded the one here: http://www.dll-files.com/dllindex/dll-files.shtml?msvcr90d), it still gives an error. Might be a different revision however.. check your Visual C++ directories to see if you can find the one you have and copy it to the script or system folder. If you still run into problems, then how you export it is probably the problem as doudou has pointed out.

Ah, and you might not want to feed into trancexx's occasional hazing lol. Everyone has to start learning somewhere.

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Then solution is http://www.microsoft.com/downloads/details.aspx?FamilyID=9b2da534-3e03-4391-8a4d-074b9f2bc1bf&displaylang=en ?

Your program is very nice. But could you make it show how to call functions from dll? it only lists functions from dll but it doesn't show what arguments they take and what type they need to be. That's just a feature request.

Edited by E1M1

edited

Share this post


Link to post
Share on other sites

Hmm, a redistributable is probably the way to get that DLL properly registered, though you'll need to do that for every machine you run your code on. (I had forgotten about regsvr32 which is needed for some DLL's) I would however suggest you somehow bind the C++ library to your EXE file (don't ask me how - but this is what is supposedly done for AutoIt). Or you could go the redistributable route.. you might need the 2008 SP1 Redistrubtable though.

As far as my Import/Export viewer, its impossible to know what a function's call structure is, unless its using C++ name mangling, or somehow there is debug information embedded which gives that information. The usual method for finding out information on Windows API calls is going to MSDN. For other DLL's, you'll need to get the information from the source.

Share this post


Link to post
Share on other sites

Hmm seems like it's not only thing it requires.


edited

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

Problem #2: AutoIt cannot use exports with dllexport calling convention. Define DLL as __stdcall and use DEF file to declare your exports.

I would also like to point out that there is nothing wrong with the dllexport pragma, and it is also not a calling convention.

Back on the main topic though, you can configure Visual Studio to include the MSVC++ library directly in your dll instead of calling the installed copy (and it works even without being installed). Go to the project properties and change the value "Runtime Library" on the [Configuration Properties > C/C++ > Code Generation] page. Set it to "multithreaded" or "multithreaded debug" instead of "multithreaded dll" or "multithreaded debug dll", whichever you need.

Edited by Richard Robertson

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0