Jump to content

Delphi Dllcall to AutoIT Dllcall


ken0137
 Share

Recommended Posts

delphi code

function ComInit(comid:integer):Thandle; StdCall external '___MFCOM.DLL' name 'ComInit';
function ComExit(_handle:Thandle):integer;stdcall external '___MFCOM.DLL' name 'ComExit';
function TxRxRW(_handle:THandle):pchar; stdcall external '___MFCOM.DLL' name 'TxRxRW';

function InitializeWinIo():Boolean;stdcall;External'WinIO.dll';  
procedure ShutdownWinIo();stdcall;External'WinIO.dll';       
function GetPortVal(wPortAddr:word;pdwPortVal:pdword;bSize:byte):Boolean;stdcall;External'WinIO.dll';   
function SetPortVal(wPortAddr:word;dwPortVal:dword;bSize:byte):Boolean;stdcall;External'WinIO.dll';
.................
..................
................
comhandle:=cominit(3);
  i:=0;
  while i<5 do
  begin
    p_card:=txrxrw(comhandle);
    s:=p_card;
    if s<>'' then
    begin
      i:=0;
      break;
    end
    else
    begin
      i:=i+1;
      sleep(500);
    end;

i want use ___MFCOM.DLL in AU3

how should i do?

the function

comhandle:=cominit(3);

p_card:=txrxrw(comhandle);

how to transform them?

thank you

Link to comment
Share on other sites

delphi code

function ComInit(comid:integer):Thandle; StdCall external '___MFCOM.DLL' name 'ComInit';
function ComExit(_handle:Thandle):integer;stdcall external '___MFCOM.DLL' name 'ComExit';
function TxRxRW(_handle:THandle):pchar; stdcall external '___MFCOM.DLL' name 'TxRxRW';

function InitializeWinIo():Boolean;stdcall;External'WinIO.dll';  
procedure ShutdownWinIo();stdcall;External'WinIO.dll';       
function GetPortVal(wPortAddr:word;pdwPortVal:pdword;bSize:byte):Boolean;stdcall;External'WinIO.dll';   
function SetPortVal(wPortAddr:word;dwPortVal:dword;bSize:byte):Boolean;stdcall;External'WinIO.dll';
.................
..................
................
comhandle:=cominit(3);
  i:=0;
  while i<5 do
  begin
    p_card:=txrxrw(comhandle);
    s:=p_card;
    if s<>'' then
    begin
      i:=0;
      break;
    end
    else
    begin
      i:=i+1;
      sleep(500);
    end;

i want use ___MFCOM.DLL in AU3

how should i do?

the function

comhandle:=cominit(3);

p_card:=txrxrw(comhandle);

how to transform them?

thank you

I would expect (guess) that the translation of the use of

function ComInit(comid:integer):Thandle; StdCall external '___MFCOM.DLL' name 'ComInit';

would be like this,

$comid = 3;??? the port id you want which must be an integer.
$res = DllCall("MFCOM.DLL","hwnd","ComInit","int",$comid)
MsgBox(0,"result from ComInit func is","0x" & Hex($res[0]))
comhandle = $res[0]

See the help for DllCall.

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

  • 2 weeks later...

failed

are there anybody can help me?

delphi

function ComInit(comid:integer):Thandle; StdCall external '___MFCOM.DLL' name 'ComInit';
function ComExit(_handle:Thandle):integer;stdcall external '___MFCOM.DLL' name 'ComExit';
function TxRxRW(_handle:THandle):pchar; stdcall external '___MFCOM.DLL' name 'TxRxRW';
。。。。
comhandle:=cominit(3);
  i:=0;
  while i<5 do
  begin
    p_card:=txrxrw(comhandle);
    s:=p_card;
    if s<>'' then
    begin
      i:=0;
      break;
    end
    else
    begin
      i:=i+1;
      sleep(500);
    end;

to autoit?

AU3

How?
Link to comment
Share on other sites

So far there is nothing stopping you for attempting it. And if you says its too hard, then you should try something different then move to DllCalls.

Cheers,

Brett

Link to comment
Share on other sites

failed

are there anybody can help me?

delphi

function ComInit(comid:integer):Thandle; StdCall external '___MFCOM.DLL' name 'ComInit';
 function ComExit(_handle:Thandle):integer;stdcall external '___MFCOM.DLL' name 'ComExit';
 function TxRxRW(_handle:THandle):pchar; stdcall external '___MFCOM.DLL' name 'TxRxRW';
 。。。。
 comhandle:=cominit(3);
   i:=0;
   while i<5 do
   begin
     p_card:=txrxrw(comhandle);
     s:=p_card;
     if s<>'' then
     begin
       i:=0;
       break;
     end
     else
     begin
       i:=i+1;
       sleep(500);
     end;

to autoit?

AU3

How?
"Failed" doesn't tell us very much but I think that @error will be 3 which means that the function is not found in the dll.

I found a copy of MFCOM.DLL and used dllexp.exe to see what functions there are in it and it found none, so I have no idea how to use the dll I'm afraid. Maybe someone who knows more about this can help.

Do you have to use mfcom.dll? Could you use an AutoIt udf like the one in my signature?

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

C++ 6

MFC Extensino DLL (using shared MFC DLL)

AUTOIT_MFC_DLL.cpp

ADD ON cpp FILE

#ifdef AUTOIT_MFC_DLL_EXPORTS

AUTOIT_MFC_DLL ===> DLL LIBRARY appname

_EXPORTS

AUTOIT_MFC_DLL_EXPORTS

#define AUTOIT_MFC_DLL_API __declspec(dllexport)

AUTOIT_MFC_DLL ===> DLL LIBRARY appname

_API

__declspec(dllexport)

AUTOIT_MFC_DLL_API __declspec(dllexport)

#define AUTOIT_MFC_DLL_API __declspec(dllimport)

AUTOIT_MFC_DLL ===> DLL LIBRARY appname

_API

__declspec(dllimport)

AUTOIT_MFC_DLL_API __declspec(dllimport)

AUTOIT_MFC_DLL.dll

#include "stdafx.h"
#include <afxdllx.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


#ifdef  AUTOIT_MFC_DLL_EXPORTS
#define  AUTOIT_MFC_DLL_API __declspec(dllexport)
#else
#define  AUTOIT_MFC_DLL_API __declspec(dllimport)
#endif


extern "C"
{
AUTOIT_MFC_DLL_API int AfxMsBox(LPCTSTR);
AUTOIT_MFC_DLL_API int CString_Find(int,LPSTR ,LPSTR);
AUTOIT_MFC_DLL_API LPSTR CString_Insert(int,LPSTR,LPSTR);
AUTOIT_MFC_DLL_API int CString_Get_Length(LPSTR);
AUTOIT_MFC_DLL_API LPSTR CString_Replace(LPSTR,LPCTSTR,LPCTSTR);
};



static AFX_EXTENSION_MODULE AUTOIT_MFC_DLLDLL = { NULL, NULL };

extern "C" int APIENTRY
DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
    // Remove this if you use lpReserved
    UNREFERENCED_PARAMETER(lpReserved);

    if (dwReason == DLL_PROCESS_ATTACH)
    {
        TRACE0("AUTOIT_MFC_DLL.DLL Initializing!\n");

        // Extension DLL one-time initialization
        if (!AfxInitExtensionModule(AUTOIT_MFC_DLLDLL, hInstance))
            return 0;

        // Insert this DLL into the resource chain
        // NOTE: If this Extension DLL is being implicitly linked to by
        //  an MFC Regular DLL (such as an ActiveX Control)
        //  instead of an MFC application, then you will want to
        //  remove this line from DllMain and put it in a separate
        //  function exported from this Extension DLL.  The Regular DLL
        //  that uses this Extension DLL should then explicitly call that
        //  function to initialize this Extension DLL.  Otherwise,
        //  the CDynLinkLibrary object will not be attached to the
        //  Regular DLL's resource chain, and serious problems will
        //  result.

        new CDynLinkLibrary(AUTOIT_MFC_DLLDLL);
    }
    else if (dwReason == DLL_PROCESS_DETACH)
    {
        TRACE0("AUTOIT_MFC_DLL.DLL Terminating!\n");
        // Terminate the library before destructors are called
        AfxTermExtensionModule(AUTOIT_MFC_DLLDLL);
    }
    return 1;   // ok


}

int AfxMsBox(LPCTSTR TXT1)
{
if (AfxMessageBox(TXT1)) {return 1;}
return 0;
}

int CString_Find(int nStart ,LPSTR FSTR ,LPSTR FSUBSTR)
{
return CString(FSTR).Find(FSUBSTR,nStart);
}

LPSTR CString_Insert(int nIndex ,LPSTR ISTR ,LPSTR ISUBSTR)
{
CString ISTR2 = ISTR;
ISTR2.Insert(nIndex,ISUBSTR);
return (LPSTR) ISTR2.GetBuffer(ISTR2.GetLength());
}

int CString_Get_Length(LPSTR GLSTR)
{
return CString(GLSTR).GetLength();
}

LPSTR CString_Replace(LPSTR RSTR, LPCTSTR ipszOld , LPCTSTR ipszNew)
{
CString RSTR2 = RSTR;
RSTR2.Replace(ipszOld,ipszNew);
return (LPSTR) RSTR2.GetBuffer(RSTR2.GetLength());
}

Call AUTOIT_MFC_DLL.dll (Autoit Code)

$DllOpen = DllOpen(@ScriptDir & "\AUTOIT_MFC_DLL.dll")

AfxMsBox("Hello World")

MsgBox(0,"CString_Insert",CString_Insert(6 ,"AUTOIT" , "_MFC_DLL"))
MsgBox(0,"CString_Find",CString_Find(0 ,"Hello World" ,"World"))
MsgBox(0,"CString_Get_Length",CString_Get_Length("Hello World"))
MsgBox(0,"CString_Replace",CString_Replace("Hello World", "World" , "Test"))


Func AfxMsBox($TXT = "")
$DllCall = DllCall($DllOpen,"int:cdecl","AfxMsBox","str",$TXT)
Return $DllCall[0]
EndFunc


Func CString_Find($nStart = 0 ,$FSTR = "" ,$FSUBSTR = "")
$DllCall = DllCall($DllOpen,"int:cdecl","CString_Find","int",$nStart,"str",$FSTR,"str",$FSUBSTR)
Return $DllCall[0]
EndFunc

Func CString_Insert($nIndex = 0 ,$STR = "" ,$SUBSTR = "")
$DllCall = DllCall($DllOpen,"str:cdecl","CString_Insert","int",$nIndex ,"str",$STR ,"str",$SUBSTR)
Return $DllCall[0]
EndFunc

Func CString_Get_Length($GLSTR = "")
$DllCall = DllCall($DllOpen,"int:cdecl","CString_Get_Length","str",$GLSTR)
Return $DllCall[0]
EndFunc

Func CString_Replace($RSTR = "" , $ipszOld = "" , $ipszNew = "" )
$DllCall = DllCall($DllOpen,"str:cdecl","CString_Replace","str",$RSTR,"str",$ipszOld ,"str", $ipszNew)
Return $DllCall[0]
EndFunc

DllClose($DllOpen)
Edited by wolf9228

صرح السماء كان هنا

 

Link to comment
Share on other sites

  • 3 weeks later...

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...