Jump to content
Sign in to follow this  
matwachich

C DLL Question

Recommended Posts

matwachich

Hi! I have a question:

- Why the hell would an application crash when I launch it from windows explorer, and works all fine when I launch it from command prompt?????

More details:

- It's an app that uses a DLL written in pure C of mine

- The app also runs well when launched from SciTE (think it's a problem with the stdout...)

- The module concerned in the crash is msvcrt.dll

- All parts of the dll (event external libraries) are compiled using the same GCC (no any .NET sh*t)

- Not only with AutoIt, even if I try to use this DLL with FreeBasic, I have the same crash

- Befor, the DLL was not crashing this way, but I made many changes (and I didn't tracked them) since the last good version, so I have no idea where it comes from

Big thanks! :)

Share this post


Link to post
Share on other sites
funkey

I cannot see what's wrong without code, but once I had the same problem with an app not a DLL ritten in C. Problem was that the command line was different when starting the app from windows than starting the app from console. I parsed the app for first command line parameter (the path) and on console it was only 'app.exe' and in windows it was 'C:app.exe'. Something like that.

  • Like 1

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Share this post


Link to post
Share on other sites
matwachich

Thanks!

But I don't think the problem is here, because I don't make any use of cmd line params in the dll nor in the app using the dll.

The code... first It's verry huge! (a total of 11370 lines with 6470 lines of code), and secondly, I don't yet know if I will release the code...

It's a DLL in pure C, using as external libs: GLFW, SOIL and inih

It's Object Oriented Syntax but with C. I mean all data structures are in opaque structs (only the dll know the members) and they are handled by the user with functions like: Sprite_Create (allocation), Sprite_Destroy (free), Sprite_SetPos, Sprite_GetPos ...

Gonna fill the functions with printf and test!

Share this post


Link to post
Share on other sites
matwachich

Problem solved! Thanks to the printf function!

It was a not-completly initialized struct:

- I allocate a sort of global and internal struct that contains many internal informations. One of these informations is a flag (0/1) to say if a Render Window is opened. This flag was not initialized to 0 when creating th structure.

- When I call the OpenWindow function, this function checks the flag to see if it should open a window or not. And here was the problem (the flag wasn't initialized)

What I don't understand yet (although my problem was solved by initializing the flag to 0) is why this caused problem only when launching the application from Windows Explorer???

Thanks for who readed me!

Share this post


Link to post
Share on other sites
Richard Robertson

Different program subsystems may or may not initialize values differently. You should never rely on uninitialized values because this sort thing can happen.

  • Like 1

Share this post


Link to post
Share on other sites
Shaggi

Why create an oop c system, when there is an obvious alternative...

If you run the code in debug mode, your debugger should tell you, that youre accessing uninitialized variables.

  • Like 1

Ever wanted to call functions in another process? ProcessCall UDFConsole stuff: Console UDFC Preprocessor for AutoIt OMG

Share this post


Link to post
Share on other sites
matwachich

What alternative?

Share this post


Link to post
Share on other sites
Richard Robertson

C++. OOP on top of C.

Share this post


Link to post
Share on other sites
matwachich

But by doing this, it will not be usable with AutoIt, which my first goal!

And I don't know why (perhaps because I don't master it) but I don't like C++

I'm also doing a FreeBasic wrapper to my engin, and It uses Classes

I'm near to release this engin, I just want to make a proper errors handling for it, and also (and this is the boringest thing ever!) a proper documentation (about 300 function!!!)

Share this post


Link to post
Share on other sites
Richard Robertson

AutoIt works fine with C++ dlls if you understand name mangling.

Share this post


Link to post
Share on other sites
matwachich

How can AutoIt use C++ classes???

And if it is just for making simple, standard functions, I prefer staying with C :)

Share this post


Link to post
Share on other sites
trancexx

How can AutoIt use C++ classes???

And if it is just for making simple, standard functions, I prefer staying with C :)

Every virtual class method/function is accessible by DllCallAddress() or ObjCreateInterface() for example. Number of other "ways" exist.

♡♡♡

.

eMyvnE

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  

  • Similar Content

    • Terenz
      By Terenz
      Hello,
      Someone is so kind to compile for me this DLL?
      https://github.com/stephane/libmodbus/tree/master/src/win32
      Many thanks!
    • cdeb
      By cdeb
      I'm trying to verify which is the default scanner and if it is different from what I need to propose a choice among those available.
      All this is possible with eztw32.dll however I can not make certain functions work
      Are these:
      int TWAIN_GetDefaultSourceName(LPSTR pzName)
      string TWAIN_DefaultSourceName()
      int TWAIN_GetSourceList(void)
      source: http://www.eztwain.com/pub/eztp/EZTwain_User_Guide.pdf
      I tried this way but they do not work:
      Local $pzName
      $pzName = DllCall($pathDLL,"int","TWAIN_DefaultSourceName") ;
      $rc = DllCall($pathDLL,"int","TWAIN_GetDefaultSourceName", "str*", $pzName) ;
      $rc = DllCall($pathDLL,"int","TWAIN_GetDefaultSourceName","str", $pzName) ;
      $rc = DllCall($pathDLL,"int","TWAIN_GetSourceList")
      $rc = DllCall($pathDLL,"int","TWAIN_GetSourceList", "NONE", "") ;
       
      Can anyone help me?
      Everything else works, here is the code:
       
      Local $pathDLL = @ScriptDir&"\_res\eztw32.dll" Local $rc = DllCall($pathDLL,'int','TWAIN_EasyVersion') if @error <> 0 then MsgBox(16+262144, "DllCall Error", "Error load eztw32.dll") else ConsoleWrite('--> eztw32.dll version: ' & $rc[0]/100 & @CRLF) $rc = DllCall($pathDLL,"int","TWAIN_IsAvailable") If @error > 0 Then MsgBox(16+262144, "DllCall Error", "Error call DLL - TWAIN_IsAvailable") if $rc[0] <> 0 then ConsoleWrite('--> TWAIN available: RC = ' & $rc[0]&@CRLF) ;;;;;;;;;;;;;;;;;;;;;; I NEED HERE ;manual select scanner Local $hwnd $rc = DllCall($pathDLL,"long","TWAIN_SelectImageSource",'hwnd',$hwnd) ConsoleWrite('--> TWAIN_SelectImageSource = ' & $rc[0]&@CRLF) if $rc[0] <> 0 then ConsoleWrite("--> TWAIN device selected"&@CRLF) else ConsoleWrite("--> no TWAIN device selected"&@CRLF) endif Else ConsoleWrite('--> TWAIN NOT available: RC = ' & $rc[0]&@CRLF) ; es: 0 endif endif thank you
    • Mannyfresh31
      By Mannyfresh31
      Hi Everybody I want know if there is someone kind enough to help me translate this code in to Autoit please don't blame me cause I'm a newbe 
      here is the code I need to translate also I want know if it's possible to look through a DLL  functions
       
      Declaration in Visual Basic 6: 
      Simply add the DLL import unit 'cashdll.bas' to your project, 
      or add following line to the declarations part: 
      Declare Function CASH_OPENCOM Lib "CASH.DLL" (ByVal CASH_COMPORT As Long) As Long 
       
      Declaration in Visual Basic 6: 
      Simply add the DLL import unit 'cashdll.bas' to your project, 
      or add following line to the declarations part: 
      Declare Sub CASH_CLOSECOM Lib "CASH.DLL" ()
       
       
      and here is the code I have written so far
      down below is the DLL attached also a screen shot of the  exit code of SciTE
      #include<Array.au3> $CashDLL = DllOpen("C:\Users\manue\Downloads\Casll DLL\cash.dll") if $CashDLL Then MsgBox (0,"","CashDLL Open",0) $HOPPER_OPENCOM = DllCall($CashDLL,"LONG","HOPPER_OPENCOM") if isarray ($HOPPER_OPENCOM) Then _Arraydisplay ($HOPPER_OPENCOM) Else MsgBox (0,"",@error,0) EndIf $HOPPER_CLOSECOM = DllCall($CashDLL,"NONE","HOPPER_CLOSECOM") if isarray ($HOPPER_CLOSECOM) Then _Arraydisplay ($HOPPER_CLOSECOM) Else MsgBox (0,"",@error,0) EndIf DllClose ($CashDLL)  
       

      cash.dll
    • marcoauto
      By marcoauto
      Ciao
      I would like to control an ATEM Video Mixer from autoit. I downloaded his SDK which is written in c ++ and I found the sequences to interface, but I was not able to convert the script to self.
      The instructions say to follow this sequence:
      and to connectTo with C++ is:
      string address = "192.168.1.240"; _BMDSwitcherConnectToFailure failureReason = 0; IBMDSwitcher switcher = null; var discovery = new CBMDSwitcherDiscovery(); discovery.ConnectTo(address, out switcher, out failureReason); From Blackmagic SDK:
      IBMDSwitcherDiscovery::ConnectTo method
      The ConnectTo method connects to the specified switcher and returns an IBMDSwitcher object interface for the switcher.
      Syntax HRESULT ConnectTo (string deviceAddress, IBMDSwitcher** switcherDevice, BMDSwitcherConnectToFailure* failReason); Parameters: deviceAddress in Network hostname or IP address of switcher to connect to. switcherDevice out IBMDSwitcher object interface for the connected switcher. failReason out Reason for connection failure as a BMDSwitcherConnectToFailure value. So, I have I tried these solutions but with non success:
      $DllName =@ScriptDir&"\BMDSwitcherAPI.dll" $result = DllCall($DllName, "none", "IBMDSwitcherDiscovery::ConnectTo" & @CRLF) ConsoleWrite("DLLCall Result: " & $result & @CRLF) and I have tried also create an Object (That I think is the best way solution):
      #include <MsgBoxConstants.au3> $oSwitcher=ObjCreate("IBMDSwitcher") If IsObj($oSwitcher) Then MsgBox(64, "", "Object $oSwitcher created successfully") EndIf $oAtem=ObjCreate("IBMDSwitcherDiscovery") If IsObj($oAtem) Then MsgBox(64, "", "Object $oAtem created successfully") EndIf $failureReason =ObjCreate("_BMDSwitcherConnectToFailure") If IsObj($failureReason) Then MsgBox(64, "", "Object $failureReason created successfully") EndIf $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc") ; Install a custom error handler Global $errore,$oSwitcher1 $oAtem.ConnectTo("192.168.1.36",$oSwitcher,$failureReason); ; This is the custom error handler Func MyErrFunc() $HexNumber = Hex($oMyError.number, 8) MsgBox(0, "", "We intercepted a COM Error !" & @CRLF & _ "Number is: " & $HexNumber & @CRLF & _ "Windescription is: " & $oMyError.windescription & @CRLF & _ "Source is: " & $oMyError.source & @CRLF & _ "Description is: " & $oMyError.description & @CRLF & _ "Helpfile is: " & $oMyError.helpfile & @CRLF & _ "Helpcontext is: " & $oMyError.helpcontext & @CRLF & _ "Lastdllerror is: " & $oMyError.lastdllerror & @CRLF & _ "Scriptline is: " & $oMyError.scriptline) EndFunc ;==>MyErrFunc But the result is:
      We intercepted a COM Error !
      Number is: 000000A9
      Windescription is: Variable must be of type 'Object'.
      Source is: 
      Description is: 
      Helpfile is: 
      Helpcontext is: 
      Lastdllerror is: 0
      Scriptline is: 17
      The BMDSwitcherAPI.dll is registered in system. Can someone help me?
      Grazie
      Marco
    • nacerbaaziz
      By nacerbaaziz
      Hi dear
      With this script you can print Unicode text in the CMD screen
      the script is  easy to use
      just you  write the text that contains Unicode in the first input
      and the script automatically reflect the code in the second input
       you can copy the text to the clipboard
      or you can try printing the text in the CMD window
      I apologize to everyone for colors and shape if not appropriate
      I'm a blind man and I do not see
      Thank you for your understanding
      Greetings to all of youCmdUtM.au3
×