c++ - How to address C4191 warning around calls to GetProcAddress with FARPROC? -


recently tried use /wall visual c++ option enable warnings , found following code:

typedef bool ( winapi * tiswow64processfunction )( handle, bool* ); tiswow64processfunction iswow64processfunction = reinterpret_cast<tiswow64processfunction> (     ::getprocaddress( kernel32dllhandle, "iswow64process" ) ); 

spawned c4191:

warning c4191: 'reinterpret_cast' : unsafe conversion 'farproc' 'tiswow64processfunction' calling function through result pointer may cause program fail 

if use c-style cast same warning appears mentions "type cast" instead of "reinterpret_cast".

the same warning repeated case call getprocaddress() , convert return value usable function pointer.

how address these warnings? need make alterations code?

you casting farproc (function pointer no args) function pointer args. hugely dumb thing result in stack corruption.

now turns out getprocaddress() doesn't return farproc , know you're doing -- compiler doesn't know , feels obliged warn you.

the way can silence using #pragma or compiler switch turn off warning. ugly , messy, windows programming you. :-)


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -