0

I'm trying to get rid of a warning in my code, but I'm in way over my head here...

The original code row looks like this:

FeasaCom_Open=(tFeasaCom_Open)(GetProcAddress(static_cast<HMODULE>(hFeasaComDLL), "FeasaCom_Open"));

The warning that's thrown is:

warning: use of old-style cast

I've tried to fix this by re-writing it in this way:

FeasaCom_Open=static_cast<tFeasaCom_Open>(GetProcAddress(static_cast<HMODULE>(hFeasaComDLL), "FeasaCom_Open"));

But then I get the warning:

error: static_cast from 'FARPROC' (aka 'int (*)() __attribute__((stdcall))') to 'tFeasaCom_Open' (aka 'int (*)(int, char *) __attribute__((stdcall))') is not allowed

The definition of FeasaCom_Open is:

typedef int (__stdcall *tFeasaCom_Open)(int CommPort, char * Baudrate);

And declaration is:

tFeasaCom_Open FeasaCom_Open;

I probably don't need to tell you this, but declaration of GetProcAddress looks like this:

WINBASEAPI FARPROC WINAPI GetProcAddress (HMODULE hModule, LPCSTR lpProcName);

And FARPROC:

typedef int (WINAPI *FARPROC) ();

I've tried to fix this, but I don't really know what I'm doing here... I'm using Qt 5.9.6 with MinGW 5.3.0 32-bit, if that's any help.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • Similar to [this question](https://stackoverflow.com/q/57973305/10871073) from me! Although there is no formal answer there, you may find some of the discussion helpful. – Adrian Mole Sep 03 '20 at 11:00
  • 6
    you need to `reinterpret_cast` not `static_cast` – Alan Birtles Sep 03 '20 at 11:23
  • Unrelated to your issue, why do you have to cast `hFeasaComDLL`? Why is it not an `HMODULE` already? After all, that's what `LoadLibrary` and friends return. Also, you should probably not be using the 32-bit version of MinGW. It hasn't been updated in ages, and ships with rather incomplete Windows support. Go with the 64-bit version, if you must use MinGW. – IInspectable Sep 04 '20 at 11:55
  • @IInspectable Really sorry for not answering sooner! I have no idea why it's done this way. I'm using a code example from Feasa written in C for a LED Analyzer. https://www.feasa.ie/ledanalyser.html It was fairly easy to get the code example to work in C++ (Qt 5), but there was quite a few warnings to solve. Now they are all gone and the code works, that's all I need. :) I will update MinGW next time I release this software. Thanks for the tip! – Albin Dennevi Sep 09 '20 at 14:45

0 Answers0