Jump to content
Sign in to follow this  
ctl3d32

Need Help Using DLL Compiled in MATLAB

Recommended Posts

ctl3d32

Hi all!

I need help using a simple dll i created using MATLAB 2009a named fatorial.dll using MS Visual C++ in MS Visual Studio 2008.

I created a "fatorial.m" file with the following code:

CODE
function resultado = fatorial(x)

resultado = factorial(x);

The code above calculates the factorial of a given number and returns the result in variable "resultado".

The code bellow is the graphical AutoIT code:

CODE
#include <ButtonConstants.au3>

#include <EditConstants.au3>

#include <GUIConstantsEx.au3>

#include <StaticConstants.au3>

#include <WindowsConstants.au3>

#Include <GuiEdit.au3>

#Region ### START Koda GUI section ### Form=

$Form1 = GUICreate("Fatorial", 203, 115, -1, -1)

$Input1 = GUICtrlCreateInput("", 88, 8, 105, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER))

$Input2 = GUICtrlCreateInput("", 48, 80, 105, 21, BitOR($ES_AUTOHSCROLL,$ES_READONLY))

$Button1 = GUICtrlCreateButton("Calcular", 64, 40, 75, 25, $WS_GROUP)

$Label1 = GUICtrlCreateLabel("Entrada:", 32, 11, 44, 17)

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE

Exit

Case $Button1

$dll = DllOpen("fatorial.dll")

DllCall($dll, 0, "fatorialInitialize", "byte", 0)

$result = DllCall($dll, "long", 7, "byte", $Input1)

DllCall($dll, "none", "fatorialTerminate")

DllClose($dll)

_GUICtrlEdit_SetText($Input2, $result)

EndSwitch

WEnd

Here is the link to download the dll, since it's greater than 64k: fatorial.dll

Could someone please help me?

Thanks in advance,

Denis Pedro

Edited by ctl3d32

Share this post


Link to post
Share on other sites
ctl3d32

Updated code, but still not working.

CODE
#include <ButtonConstants.au3>

#include <EditConstants.au3>

#include <GUIConstantsEx.au3>

#include <StaticConstants.au3>

#include <WindowsConstants.au3>

#Include <GuiEdit.au3>

#Region ### START Koda GUI section ### Form=

$Form1 = GUICreate("Fatorial", 203, 115, -1, -1)

$Input1 = GUICtrlCreateInput("", 88, 8, 105, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER))

$Input2 = GUICtrlCreateInput("", 48, 80, 105, 21, BitOR($ES_AUTOHSCROLL,$ES_READONLY))

$Button1 = GUICtrlCreateButton("Calcular", 64, 40, 75, 25, $WS_GROUP)

$Label1 = GUICtrlCreateLabel("Entrada:", 32, 11, 44, 17)

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE

Exit

Case $Button1

$dll = DllOpen("fatorial.dll")

DllCall($dll, "none", "fatorialInitialize", "byte", 0)

$result = DllCall($dll, "dword", "fatorial", "dword", Int(_GUICtrlEdit_GetText($Input1)))

DllCall($dll, "none", "fatorialTerminate")

DllClose($dll)

_GUICtrlEdit_SetText($Input2, $result)

EndSwitch

WEnd

Edited by ctl3d32

Share this post


Link to post
Share on other sites
monoceres

Hi!

DllCall() returns an array so your return value is in $result[0]


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

Share this post


Link to post
Share on other sites
ctl3d32

Thanks, i will try it.

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  

×