0

some days ago i've posted a question for a win32 API stacktrace implementation with MSYS/Mingw: Win32 API stack walk with MinGW/MSYS?

The hint with the explicit loading of the dll was the correct solution. So i've restart the try to implement a stacktrace using the win32 CaptureStackBackTrace API mechanism regarding this hint. The loading of the dll works fine:

// Load the RTLCapture context function:
HINSTANCE kernel32 = LoadLibrary("Kernel32.dll");

if(kernel32 != NULL){
   std::cout << "Try to load method from kernel32.dll: CaptureStackBackTrace" << std::endl;

   typedef USHORT (*CaptureStackBackTraceType)(ULONG FramesToSkip, ULONG FramesToCapture, void* BackTrace, ULONG* BackTraceHash);
   CaptureStackBackTraceType func = (CaptureStackBackTraceType) GetProcAddress( kernel32, "RtlCaptureStackBackTrace" );

   if(func==NULL){
       std::cout << "Handle for CaptureStackBackTrace could't loded! Stop demo!."<< std::endl;
       FreeLibrary(kernel32);
       kernel32 = NULL;
       func = NULL;
       exit(1);
   }

   void *array[63];
   int i,num = 0;

   std::cout << "Try to call CaptureStackBackTrace..."<< std::endl;
   num = CaptureStackBackTraceType( 1, 32, array, NULL );}

But i got trouble if i call the CaptureStackBackTraceType method and running in type convertion issues:

stacktrace.cpp:138: error: functional cast expression list treated as compound e xpression stacktrace.cpp:138: error: invalid conversion from USHORT (*)(ULONG, ULONG, voi d*, ULONG*)' toUSHORT'

I think this issue may be due to type differences between MSYS/MinGW and the dll definitions. Defining the USHORT explicitly #define USHORT unsigned short has no effect.

Has anyone an idea how i could solve this issue? I would be deeply gratefull for any hint.

Best regards, Christian

Community
  • 1
  • 1
Hellhound
  • 511
  • 2
  • 9
  • 21

1 Answers1

2

In the last stament, you need to invoke the function using function pointer func. So it should be num = func( 1, 32, array, NULL ); Otherwise, you are trying to create an unnamed object of type CaptureStackBackTraceType and trying it to convert to an int. Since the conversion doesn't exist, compiler is issuing an error.

Naveen
  • 74,600
  • 47
  • 176
  • 233