• C

Nonstandard extension used

When compiling my program, the following line of code causes a warning which I list after the code.

Escape(hdcPrn, SETABORTPROC, NULL, (LPSTR)lpAbortProc, (LPSTR)NULL);

This generates the following warning:

C4001 non standard extension used - 'cast of function pointer to data pointer'

Getting help on this warning gives the following:

C4001 non standard extension used - 'extension'
The given non standard language extension was used when the /Ze option was specified.
If the /Za option has been specified, this condition generates a syntax error. (warning levels 1, 4)

What can I do to overcome this?
Chris_mAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

yonatCommented:
The 4th parameter (LPSTR)lpAbortProc causes the warning.
Apparently, lpAbortProc is a pointer to a function. You are
casting it a pointer to string (data). This is dangerous, since
the memory pointed by lpAbortProc may not contain valid string
data (7 bit characters, terminated by '\0'). This memory
contains the code of the function.
Make sure that lpAbortProc is indeed the correct argument to
this function. If you are trying to pass the *name* of the
function (for example "MyAbortFunc") than this will not work. If
this is what you are trying to do, you need to save the name
somewhere *as a string* and pass that string.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ramshankCommented:
I you are using a C++ compiler to compile your C program then you  will get this warning with the /Ze option , because the microsoft extension has been  enabled . You may get same warning if you use  Single line comment  "// " in a C code . You can disable this warning by inserting the
          #pragma warning(disable:4001)
into your code.
0
Chris_mAuthor Commented:
lpAbortProc is a FARPROC data type and is a procedure instance address returned by a MakeProcInstance function.  I have coded the same as described by Peter Norton on page 726 of Eindows 3.1 Power Programming Techniques, 2nd edition; and page 912 of Petzolds Programming under Windows 3.1.  The Petzold book that I use is the german edition, so the english edition may have the example on a different page.
The code is as follows:
lpAbortDlg = MakeProcInstance((FARPROC)AbortPrintDlg, hInst);
hDlgAbort = CreateDialog(hInst, "Abort Print", (FARPROC)lpAbortDlg);
lpAbortProc = MakeProcInstance((FARPROC)PrintAbortProcedure, hInst);
Escape(hdcPrn, SETABORTPROC, NULL, (LPSTR)lpAbortProc, (LPSTR)NULL);
0
Powerful Yet Easy-to-Use Network Monitoring

Identify excessive bandwidth utilization or unexpected application traffic with SolarWinds Bandwidth Analyzer Pack.

yonatCommented:
FARPROC is a pointer to a function. If you check the memory
pointed by it you will find the machine instructions of the
function.
LPSTR is a pointer to a null terminated text string. It should
point to a buffer that contains 7-bit characters, terminated by
the null character '\0'.
The is a very little chance that the machine instructions of the
function also happen to be 7-bit characters terminated by '\0'.
This means the the code probably contains an error, and that
the compiler is right to issue a warning.
It is strange that such an example appears in Petzold. Maybe you
should check the errata, or the English version.
You can try changing the cast from (LPSTR)lpAbortProc to
(FARPROC)lpAbortProc - maybe that is the typo.
0
Chris_mAuthor Commented:
I changed the cast to (FARPROC) lpAbortProc but that produces two warnings, namely:

    different levels of indirection
    ESCAPE: different types: parameter 4

I have tried all sorts of things -- apart from changing compiler switches --  to no avail.  By the way, I have a third book which uses the same code for the SETABORTPROC Escape.

Regards
0
yonatCommented:
I wrote:

> You can try changing the cast from (LPSTR)lpAbortProc to
> (FARPROC)lpAbortProc - maybe that is the typo.

And may a typo myself! This should have been:
(FARPROC*)lpAbortProc

Hope this helps.
0
Chris_mAuthor Commented:
I have been on holiday, appologies for the delay.
If I make the cast (FARPROC*)lpAbortProc, I get the C4001 warning again.

Attention ramshank: I will disable the warning as a last resort, but I am really interested in what is causing the warning. What is interesting is that the the same cast is used in other Escape calls without provoking a warning.
0
Chris_mAuthor Commented:
Adjusted points to 300
0
yonatCommented:
What is the declaration of lpAbortProc?
Can you cast it to FARPROC* without getting warning C4001
somewhere else in your program?
0
Chris_mAuthor Commented:
The declaration is
  FARPROC  lpAbortProc

I cannot cast it to FARPROC* anywhere else in the program without getting warning C4001
0
yonatCommented:
Aha - try to pass &lpAbortProc instead of lpAbortProc.

Hope this solves your problem.
0
Chris_mAuthor Commented:
Do I understand you correctly?  If you want me to change the declaration frpm FARPROC lpAbortProc to
FARPROC &lpAbortProc, then this does not compile.            
0
yonatCommented:
No, the declaration remains the same. But instead of passing
lpAbortProc as an argument to Escape(), try passing &lpAbortProc:

Escape( hdcPrn,
        SETABORTPROC,
        NULL,
        &lpAbortProc, // this is what I mean
        NULL);

0
Chris_mAuthor Commented:
When I do what you suggest, the program compiles without giving a warning, but, when running a General Protection Fault (Trap 13(0DH)is caused.
0
yonatCommented:
Try checking for the validity of hdcPrn and lpAbortProc before calling Escape().
0
Chris_mAuthor Commented:
The validity of hdcPrn and lpAbortProc is ok
0
yonatCommented:
Maybe the GPF is caused by some other piece of code?

You can try putting trace statements before Escape(), after Escape() and inside PrintAbortProcedure() to see when the GPF actually occurs.
0
Chris_mAuthor Commented:
The GPF occurs as soon as the PrintAbortProc() function is called.  I put a breakpoint on the first line of code in the function and got a GPF.  With a breakpoint before calling PrintAbortProc(), no GPF.
0
yonatCommented:
OK, how is PrintAbortProcedure defined?
0
Chris_mAuthor Commented:
BOOL FAR PASCAL PrintAbortProc(HDC hdcPrn, short code)
{
MSG msg;

while(!bUserAbort && PeekMessage(%msg, 0, 0, 0, PM_REMOVE)){
if(!hDlgAbort || !IsDialogMessage(hDlgAbort, &msg)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return !bUserAbort
}
0
yonatCommented:
Seems fine. Just to make sure: Try passing &PrintAbortProc instead of &lpAbortProc, since MS now say not to use MakeProcInstance().
It shouldn't make a difference, but it's worth a check.
0
Chris_mAuthor Commented:
I am not sure that I understand what you mean.
0
yonatCommented:
The documuentation for MakeProcInstance sais:

"The MakeProcInstance function is obsolete. Win32 functions can be called directly.
This function is provided only for compatibility with 16-bit versions of Windows. Win32-based applications should not use this function."

So it may be a good idea to use the function address directly, instead of using MakeProcInstance.
0
Chris_mAuthor Commented:
I am using a 16 bit version of windows so I must continue using the MakeProcInstance function.
0
yonatCommented:
Sorry. I give up.

Godd luck!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.