Jump to content

Calling my own dll causes crash.


Recommended Posts

Sorry for being needy this last couple of days but I'm just running into problem after problem.

Today I tried to make a dll that would just wrap another function, but it just keeps on crashing :)

Here's my c++ code:

#include <windows.h>
extern "C" __declspec(dllexport) void _SetPixel(HDC dc,int x, int y, unsigned int color)
{

SetPixel(dc,x,y,color);

}

And here's my autoit code:

#include <GDIPlus.au3>
#include <Winapi.au3>
$hwnd=GUICreate("hello",300,200)
GUISetSTate()


_GDIPlus_Startup()
$graphics=_GDIPlus_GraphicsCreateFromHWND($hwnd)
_GDIPlus_GraphicsClear($graphics,0xFFFFFFFF)
$dc=_GDIPlus_GraphicsGetDC($graphics)
DllCall("GDIplusplus.dll","none","_SetPixel","ptr",$dc,"int",10,"int",10,"dword",0xFF0000)
Do
    $msg=GUIGetMsg()
Until $msg=-3

_GDIPlus_GraphicsReleaseDC($graphics,$dc)
_GDIPlus_GraphicsDispose($graphics)
_GDIPlus_Shutdown()

I can see that the pixel gets painted and everything but right after that it's just a big crash!

Ps. I do know that I could call the Setpixel function like this: DllCall("gdi32.dll", "int", "SetPixel", "ptr", $dc, "int", 10, "int", 10, "dword",0xFF0000)

but I'm after the principle.

:P

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

See the Remarks of DllCall reference in helpfile. Particularly the paragraph about calling conventions.

Thanks, I got it working :)

How do I make a dll that uses stdcall instead?

__stdcall gives me lots of errors in Visual studio 2008..

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

  • Moderators

Thanks, I got it working :)

How do I make a dll that uses stdcall instead?

__stdcall gives me lots of errors in Visual studio 2008..

Why would you bother with stdcall?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Why would you bother with stdcall?

I really don't know, but since i never even saw the "Function DllCallint:cdecl" syntax before I figured that stdcall was some sort of standard that would be good to follow or something.

But I really don't know that much about this so I guess I will do fine with cdecl. :)

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

  • Moderators

I really don't know, but since i never even saw the "Function DllCallint:cdecl" syntax before I figured that stdcall was some sort of standard that would be good to follow or something.

But I really don't know that much about this so I guess I will do fine with cdecl. :)

I write all mine in cdecl.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...