tags:

views:

51

answers:

2

Hi all,

some days ago i've posted a question for a win32 API stacktrace implementation with MSYS/Mingw: http://stackoverflow.com/questions/3318564/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

+1  A: 

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
A: 

My goodness, gracious me! You are right i get routine-blinded... Thanks for the hint.

Hellhound
This needs to be a comment to my answer instead of answer itself, also you can accept the answer by clicking on the checkmark besides the answer if it solves the problem your are facing.
Naveen