Recent

Author Topic: dll call fails, how to check the specific reason, so as to solve the problem  (Read 1392 times)

Jzhen

  • New Member
  • *
  • Posts: 23
The dll written by myself can be called successfully, but when the dll that needs to be used is called, an error is reported.


Access violation at address 011D9C34 in module 'xxx.dll' Read of address 3F7FFFF8.


Is my parameter type not written correctly, or what



TRon

  • Hero Member
  • *****
  • Posts: 2435
The dll written by myself can be called successfully, but when the dll that needs to be used is called, an error is reported.
"DLL that needs to be used" as in 3th party DLL ?

Quote
Is my parameter type not written correctly, or what
How are we suppose to tell if we do not know /what/ library you are using that caused that error and in what programming language the DLL was programmed in/for, what function you called and what the original parameter declaration is, what parameter declaration you have used and what parameters you have passed ?

More information required please !
« Last Edit: February 06, 2023, 07:42:00 am by TRon »

Jzhen

  • New Member
  • *
  • Posts: 23
function MTAW(filename: string; AmplitudeTh, BarrierValueForAutoLoc, coff_TimediffBetweensta, Va, xp, xk, yp, yk, zp, zk: single; SensorForLocation: Tpindex): TMTAWSOLUTION; stdcall; external 'F:\wz_work\DelphiWork\hello word\MTAWDll.dll';




try
    MTAW('E:\\evt origin\\2021-06-29 08.21.31.evt', 1, 3, 1, 2, 2, 2, 2, 2, 2, 2, ti);

  except
    on E: Exception do
      ShowMessage(E.ClassName + ' error raised, with message : ' + E.Message);

  end;

Jzhen

  • New Member
  • *
  • Posts: 23
I don't know what language the specific three-party library is. I got this result based on an incomplete document and decompilation。

TRon

  • Hero Member
  • *****
  • Posts: 2435
I don't know what language the specific three-party library is. I got this result based on an incomplete document and decompilation。
What is the name of the library and/or where can I obtain more information about the library ? (yes, I know you wrote the exact filename "MTAWdll.dll" but what does the abbreviation MTAW mean or what did the author named the DLL ?)

If it is a 3th party library that is distributed then there usually is an accompanied header file so that you know what functions (and their declaration) are present in the library and how the parameters are suppose to be used.

If you are truly decompiling a library that is not intended to be shared (closed/undocumented library) then you are basically on your own. There are some tools available that are able to obtain some valuable information about executables and DLL's but unfortunately my Windows days are long gone (e.g. I have no idea what tools to use these days).

You could always patch the library (overtake the original functions, show the passed parameters and call the original function) in order to obtain more information or run things through a debugger (olly comes to mind if that still exists)
« Last Edit: February 06, 2023, 08:06:09 am by TRon »

Jzhen

  • New Member
  • *
  • Posts: 23

What is the name of the library and/or where can I obtain more information about the library ? (yes, I know you wrote the exact filename "MTAWdll.dll" but what does the abbreviation MTAW mean or what did the author named the DLL ?)

If it is a 3th party library that is distributed then there usually is an accompanied header file so that you know what functions (and their declaration) are present in the library and how the parameters are suppose to be used.

If you are truly decompiling a library that is not intended to be shared (closed/undocumented library) then you are basically on your own. There are some tools available that are able to obtain some valuable information about executables and DLL's but unfortunately my Windows days are long gone (e.g. I have no idea what tools to use these days).

You could always patch the library (overtake the original functions, show the passed parameters and call the original function) in order to obtain more information or run things through a debugger (olly comes to mind if that still exists)


This is a library provided to us by a third party, and the documentation is also an incomplete document, because the docking personnel have left, so there are only these remnants, and this is the first time I have come into contact with it, so many things do not know how to do it. is correct

Jzhen

  • New Member
  • *
  • Posts: 23

If you are truly decompiling a library that is not intended to be shared (closed/undocumented library) then you are basically on your own. There are some tools available that are able to obtain some valuable information about executables and DLL's but unfortunately my Windows days are long gone (e.g. I have no idea what tools to use these days).

You could always patch the library (overtake the original functions, show the passed parameters and call the original function) in order to obtain more information or run things through a debugger (olly comes to mind if that still exists)

I will try to find out how to solve it, thank you for your reply.
If you have an idea, you can reply next time



TRon

  • Hero Member
  • *****
  • Posts: 2435
This is a library provided to us by a third party, and the documentation is also an incomplete document, because the docking personnel have left, so there are only these remnants, and this is the first time I have come into contact with it, so many things do not know how to do it. is correct
That begs the question: how do you know that the parameters and types used in your declaration ...:
Code: Pascal  [Select][+][-]
  1. function MTAW(filename: string; AmplitudeTh, BarrierValueForAutoLoc, coff_TimediffBetweensta, Va, xp, xk, yp, yk, zp, zk: single; SensorForLocation: Tpindex): TMTAWSOLUTION; stdcall; external 'F:\wz_work\DelphiWork\hello word\MTAWDll.dll';
  2.  
.. are correct ?

Are you just winging/jolo it ?

If it is a library written in C then for one thing it is not using type string, rather pchar and/or pwidechar. pascal type Single is also not the same type single as used in c.

Jzhen

  • New Member
  • *
  • Posts: 23

That begs the question: how do you know that the parameters and types used in your declaration ...:
Code: Pascal  [Select][+][-]
  1. function MTAW(filename: string; AmplitudeTh, BarrierValueForAutoLoc, coff_TimediffBetweensta, Va, xp, xk, yp, yk, zp, zk: single; SensorForLocation: Tpindex): TMTAWSOLUTION; stdcall; external 'F:\wz_work\DelphiWork\hello word\MTAWDll.dll';
  2.  
.. are correct ?

Are you just winging/jolo it ?

If it is a library written in C then for one thing it is not using type string, rather pchar and/or pwidechar. pascal type Single is also not the same type single as used in c.


This is what I decompiled.
Code: Pascal  [Select][+][-]
  1. Mtawdll::MTAW(System::UnicodeString,float,float,float,float,float,float,float,float,float,float,System::DynamicArray<int>)     
  2.  

There are corresponding field descriptions in the document, but the last SensorForLocation:Tpindex is not sure, look at the naming and decompile it is an array.

The entire method name corresponds to the document, so it should be a delphi program.

« Last Edit: February 06, 2023, 08:30:49 am by Jzhen »

TRon

  • Hero Member
  • *****
  • Posts: 2435

Code: Pascal  [Select][+][-]
  1. Mtawdll::MTAW(System::UnicodeString,float,float,float,float,float,float,float,float,float,float,System::DynamicArray<int>)     
  2.  
That looks like c++ to me...

Quote
The entire method name corresponds to the document, so it should be a delphi program.
I was just going to suggest/ask if it was made with Delphi Rad Studio or something similar  :)

OK, so then C++ it is. Be aware that C classes/objects do not have an FPC equivalent.

System::DynamicArray is probably a Dynamic integer array (a pointer to an array ?)

If you know for sure the library was made with Delphi Rad Studio then you can probably use their online documentation to determine the exact type for the parameter types (and then find/locate the FreePascal/Lazarus equivalent).

For example:  unicodestring
« Last Edit: February 06, 2023, 08:51:02 am by TRon »

Jzhen

  • New Member
  • *
  • Posts: 23


If you know for sure the library was made with Delphi Rad Studio then you can probably use their online documentation to determine the exact type for the parameter types (and then find/locate the FreePascal/Lazarus equivalent).


Make sure it is delphi.
I'm thinking about how to find the corresponding information

TRon

  • Hero Member
  • *****
  • Posts: 2435
I'm thinking about how to find the corresponding information
I edited my previous post to include an example for unicodestring.

Here it is for System::DynamicArray

It is tedious but do-able. Although i have no idea if you are able to accomplish this with freepascal/lazarus. The documentation is rather explicit about some of these types being Delphi (class) compatible. FPC/Lazarus <> Delphi on binary/VMT level.

Jzhen

  • New Member
  • *
  • Posts: 23

I edited my previous post to include an example for unicodestring.

Here it is for System::DynamicArray

It is tedious but do-able. Although i have no idea if you are able to accomplish this with freepascal/lazarus. The documentation is rather explicit about some of these types being Delphi (class) compatible. FPC/Lazarus <> Delphi on binary/VMT level.

Thank you very much, I have already got the source code from a third party, and I don't need to guess the data type anymore.

How can I debug the method of entering the dll source code, similar to the function of java entering the source code, I want to see the direction of the specific data and code, so as to know the cause of the error.

This is my first time using delphi. Possible problems than Xiaobai, I hope you can provide your guidance.

« Last Edit: February 07, 2023, 03:09:43 am by Jzhen »

TRon

  • Hero Member
  • *****
  • Posts: 2435
Thank you very much,
You're welcome.

Quote
I have already got the source code from a third party, and I don't need to guess the data type anymore.
That makes things /a lot/ easier.

Quote
How can I debug the method of entering the dll source code, similar to the function of java entering the source code, I want to see the direction of the specific data and code, so as to know the cause of the error.
That depends on what kind of source-code you now actually got.

Do you now have the complete source-code of the library (thus also including the implementation of the library functions itself, in which case you can actually see what happens with the parameters) or only the library header sources ?

I am guesstimating that it is the latter.

Quote
This is my first time using delphi. Possible problems than Xiaobai, I hope you can provide your guidance.
Delphi is really not my area of expertise (anymore). The last Delphi that I used was version 7.

In those days you could use the integrated debugger to set a breakpoint on the call to the library and inspect all (declared) values. Then debugging your way through the function to see what happens with the different parameters.

If you are working with Delphi then you are also actually also in the wrong forums as we usually discuss FreePascal/Lazarus here. There is some common ground between Delphi and FPC/Lazarus because FPC/Lazarus tries to be Delphi compatible /at source-level/ but as soon as you are talking Delphi specifics then this isn't really the right place to discuss it.

I do not know if there is someone else around that is able to chime in (and/or if it is allowed). (If even to mention where TS should go for Delphi specific questions these days).

What Delphi version/type are we talking about specifically ? (there is a long list of accumulated releases each with their own quirks over the years)

Jzhen

  • New Member
  • *
  • Posts: 23



That depends on what kind of source-code you now actually got.

Do you now have the complete source-code of the library (thus also including the implementation of the library functions itself, in which case you can actually see what happens with the parameters) or only the library header sources ?

I am guesstimating that it is the latter.


I have got the source code. Now I just need to debug the method. Thank you again


 

TinyPortal © 2005-2018