[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Nonstandard extension used

Posted on 1997-06-29
25
Medium Priority
?
1,494 Views
Last Modified: 2008-03-17
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?
0
Comment
Question by:Chris_m
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 12
  • 12
25 Comments
 
LVL 5

Accepted Solution

by:
yonat earned 1200 total points
ID: 1251843
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
 
LVL 1

Expert Comment

by:ramshank
ID: 1251844
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
 

Author Comment

by:Chris_m
ID: 1251845
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 5

Expert Comment

by:yonat
ID: 1251846
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
 

Author Comment

by:Chris_m
ID: 1251847
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
 
LVL 5

Expert Comment

by:yonat
ID: 1251848
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
 

Author Comment

by:Chris_m
ID: 1251849
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
 

Author Comment

by:Chris_m
ID: 1251850
Adjusted points to 300
0
 
LVL 5

Expert Comment

by:yonat
ID: 1251851
What is the declaration of lpAbortProc?
Can you cast it to FARPROC* without getting warning C4001
somewhere else in your program?
0
 

Author Comment

by:Chris_m
ID: 1251852
The declaration is
  FARPROC  lpAbortProc

I cannot cast it to FARPROC* anywhere else in the program without getting warning C4001
0
 
LVL 5

Expert Comment

by:yonat
ID: 1251853
Aha - try to pass &lpAbortProc instead of lpAbortProc.

Hope this solves your problem.
0
 

Author Comment

by:Chris_m
ID: 1251854
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
 
LVL 5

Expert Comment

by:yonat
ID: 1251855
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
 

Author Comment

by:Chris_m
ID: 1251856
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
 
LVL 5

Expert Comment

by:yonat
ID: 1251857
Try checking for the validity of hdcPrn and lpAbortProc before calling Escape().
0
 

Author Comment

by:Chris_m
ID: 1251858
The validity of hdcPrn and lpAbortProc is ok
0
 
LVL 5

Expert Comment

by:yonat
ID: 1251859
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
 

Author Comment

by:Chris_m
ID: 1251860
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
 
LVL 5

Expert Comment

by:yonat
ID: 1251861
OK, how is PrintAbortProcedure defined?
0
 

Author Comment

by:Chris_m
ID: 1251862
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
 
LVL 5

Expert Comment

by:yonat
ID: 1251863
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
 

Author Comment

by:Chris_m
ID: 1251864
I am not sure that I understand what you mean.
0
 
LVL 5

Expert Comment

by:yonat
ID: 1251865
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
 

Author Comment

by:Chris_m
ID: 1251866
I am using a 16 bit version of windows so I must continue using the MakeProcInstance function.
0
 
LVL 5

Expert Comment

by:yonat
ID: 1251867
Sorry. I give up.

Godd luck!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question