Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Errors compiling MIDL generated code

252 views
Skip to first unread message

nicolasr

unread,
Feb 13, 2007, 7:04:13 PM2/13/07
to
Hi,

I'm trying to compile a few lines of code generated
by the Microsoft IDL compiler but it fails with errors I don't
understand. I created a new DLL project and just added
this small autogenerated code file.

//dlldata.cpp
#include <rpcproxy.h>

#ifdef __cplusplus
extern "C" {
#endif

EXTERN_PROXY_FILE( imath )

PROXYFILE_LIST_START
REFERENCE_PROXY_FILE( imath ),
PROXYFILE_LIST_END

#ifdef __cplusplus
} /*extern "C" */
#endif

The macros are defined in rpcproxy.h as follows:

#define EXTERN_PROXY_FILE(name) \
EXTERN_C const ProxyFileInfo name##_ProxyFileInfo;

#define PROXYFILE_LIST_START \
const ProxyFileInfo * aProxyFileList[] = {

#define REFERENCE_PROXY_FILE(name) \
& name##_ProxyFileInfo

#define PROXYFILE_LIST_END \
0 };


Problem:
Trying to compile it as it is leads to:
W8054 Style of function definition is now obsolete
for the EXTERN_PROXY_FILE line and
E2258 Declaration was expected
for PROXYFILE_LIST_START (probably a follow up)

I then replaced the EXTERN_PROXY_FILE line with

EXTERN_C const ProxyFileInfo imath_ProxyFileInfo;

which gets me
E2141 Declaration syntax error

As a next test I simply removed EXTERN_C. That brings up:
E2304 Constant variable 'ProxyFileInfo' must be initialized
which seems to be nonsense???
The rpcproxy.h file I used is the one that comes with BCB5.
The declaration of ProxyFileInfo there is:

typedef struct tagProxyFileInfo
{
const PCInterfaceProxyVtblList *pProxyVtblList;
const PCInterfaceStubVtblList *pStubVtblList;
const PCInterfaceName * pNamesArray;
const IID ** pDelegatedIIDs;
const PIIDLookup pIIDLookupRtn;
unsigned short TableSize;
unsigned short TableVersion;
const IID ** pAsyncIIDLookup;
LONG_PTR Filler2;
LONG_PTR Filler3;
LONG_PTR Filler4;
}ProxyFileInfo;


I have no idea what is going wrong here. Does anyone
have an idea or could reproduce this behavior. As I said
a plain DLL project and a code file with the few lines
quoted above seems to produce this.

thanks for any help,
Nicolas

Bob Gonder

unread,
Feb 14, 2007, 10:20:58 AM2/14/07
to
nicolasr wrote:

>EXTERN_PROXY_FILE( imath )


>
>W8054 Style of function definition is now obsolete
>for the EXTERN_PROXY_FILE line and

If you don't have WIN32 defined, then that line looks like a function.
Add #include <windows.h> before your other include.


Chris Uzdavinis

unread,
Feb 14, 2007, 12:46:29 PM2/14/07
to
"nicolasr" <nicolasrREMOVE...@gmx.net> writes:

> thanks, it's getting better :-)
> Now a new error appears in rpcproxy.h:


>
> typedef struct tagProxyFileInfo
> {
> const PCInterfaceProxyVtblList *pProxyVtblList;
> const PCInterfaceStubVtblList *pStubVtblList;
> const PCInterfaceName * pNamesArray;
> const IID ** pDelegatedIIDs;
> const PIIDLookup pIIDLookupRtn;

> ...
> }ProxyFileInfo;
>
> [C++ Error] rpcproxy.h(143): E2232 Constant member
> 'tagProxyFileInfo::pIIDLookupRtn' in class without constructors
>
> Is this a compatibility issue or a bug? As I said this is the
> rpcproxy.h file that comes with BCB5.

Since this code is generated and is impossible to use correctly, it is
clearly a codegen bug. You *have* to initialize const members in the
constructor because it is never valid to initialize them later. It
may work (if you cast away const), but falls into the realm of
undefined behavior, which is in my book (with only a few specific
exceptions) a serious bug, and not a viable solution.

--
Chris (TeamB);

nicolasr

unread,
Feb 14, 2007, 12:38:48 PM2/14/07
to
thanks, it's getting better :-)
Now a new error appears in rpcproxy.h:

typedef struct tagProxyFileInfo


{
const PCInterfaceProxyVtblList *pProxyVtblList;
const PCInterfaceStubVtblList *pStubVtblList;
const PCInterfaceName * pNamesArray;
const IID ** pDelegatedIIDs;
const PIIDLookup pIIDLookupRtn;

...
}ProxyFileInfo;

[C++ Error] rpcproxy.h(143): E2232 Constant member
'tagProxyFileInfo::pIIDLookupRtn' in class without constructors

Is this a compatibility issue or a bug? As I said this is the
rpcproxy.h file that comes with BCB5.

thansk for any idea,
Nick


Bob Gonder

unread,
Feb 14, 2007, 1:28:23 PM2/14/07
to
nicolasr wrote:

>typedef struct tagProxyFileInfo
>{
> const PIIDLookup pIIDLookupRtn;

>[C++ Error] rpcproxy.h(143): E2232 Constant member
>'tagProxyFileInfo::pIIDLookupRtn' in class without constructors

It doesn't like the word 'const' on that line.

The next error you get will be because you didn't also include
objidl.h for the IRpcStubBufferVtbl structure

And that error won't go away until you remove the windows.h:

//#include <windows.h>
#pragma hdrstop
#define CINTERFACE
#include <objidl.h> // includes windows.h
#include <rpcproxy.h>

nicolasr

unread,
Feb 14, 2007, 1:26:56 PM2/14/07
to
thanks for your reply. I commented out the 'const'
and it compiles now. Unfortunately in my last post
I forgot to quote the definition of the variable type
in question. So for completeness:

typedef int __stdcall IIDLookupRtn( const IID * pIID, int * pIndex );
typedef IIDLookupRtn * PIIDLookup;

typedef struct tagProxyFileInfo
{
const PCInterfaceProxyVtblList *pProxyVtblList;
const PCInterfaceStubVtblList *pStubVtblList;
const PCInterfaceName * pNamesArray;
const IID ** pDelegatedIIDs;
const PIIDLookup pIIDLookupRtn;
...
}ProxyFileInfo;


Nick

nicolasr

unread,
Feb 14, 2007, 2:36:41 PM2/14/07
to
thanks Bob that removed all errors so far.
Since you seem to have tried to compile the
code I have one question left:
in my first post I left out one line for
simplicity. Now after reinserting this line I get
one new error. Here the full code and the error

#define CINTERFACE
#include <objidl.h>
#include <rpcproxy.h>


#ifdef __cplusplus
extern "C" {
#endif


EXTERN_PROXY_FILE( imath )

PROXYFILE_LIST_START
REFERENCE_PROXY_FILE( imath ),
PROXYFILE_LIST_END

//######## error here ###########
DLLDATA_ROUTINES( aProxyFileList, GET_DLL_CLSID )


#ifdef __cplusplus
} /*extern "C" */
#endif


[C++ Error] dlldata.cpp(32):
E2167 '__stdcall CStdStubBuffer_Release(IRpcStubBuffer *)'
was previously declared with the language 'C++'

DLLDATA_ROUTINES is defined in rpcproxy.h.
I don't understand this because of CINTERFACE shouldn't
the entire rpcproxy.h compile as C?
Any idea?

thanks again for your help.
Nick

Thomas Maeder [TeamB]

unread,
Feb 14, 2007, 4:21:56 PM2/14/07
to
Chris Uzdavinis (TeamB) <ch...@uzdavinis.com> writes:

>> Now a new error appears in rpcproxy.h:
>>
>> typedef struct tagProxyFileInfo
>> {
>> const PCInterfaceProxyVtblList *pProxyVtblList;
>> const PCInterfaceStubVtblList *pStubVtblList;
>> const PCInterfaceName * pNamesArray;
>> const IID ** pDelegatedIIDs;
>> const PIIDLookup pIIDLookupRtn;
>> ...
>> }ProxyFileInfo;
>>
>> [C++ Error] rpcproxy.h(143): E2232 Constant member
>> 'tagProxyFileInfo::pIIDLookupRtn' in class without constructors
>>
>> Is this a compatibility issue or a bug? As I said this is the
>> rpcproxy.h file that comes with BCB5.
>
> Since this code is generated and is impossible to use correctly, it
> is clearly a codegen bug.

Are you sure that it is impossible to use it correctly? Looks like an
POD-struct to me, so aggregate initialization should work.

FWIW, this:

typedef int
PCInterfaceProxyVtblList,
PCInterfaceStubVtblList,
PCInterfaceName,
IID,
PIIDLookup;

typedef struct tagProxyFileInfo
{
const PCInterfaceProxyVtblList *pProxyVtblList;
const PCInterfaceStubVtblList *pStubVtblList;
const PCInterfaceName * pNamesArray;
const IID ** pDelegatedIIDs;
const PIIDLookup pIIDLookupRtn;

} ProxyFileInfo;

int main()
{
int const i(0);
int const *ip(&i);
int const **ipp(&ip);
ProxyFileInfo pfi = { ip, ip, ip, ipp, i };
}

compiles like a charm using gcc 4.1.2.

Bob Gonder

unread,
Feb 14, 2007, 5:44:31 PM2/14/07
to
nicolasr wrote:

> Now after reinserting this line I get
>one new error. Here the full code and the error

>E2167 '__stdcall CStdStubBuffer_Release(IRpcStubBuffer *)'
>was previously declared with the language 'C++'

I don't get an error on that line with BDS2006

>DLLDATA_ROUTINES is defined in rpcproxy.h.
>I don't understand this because of CINTERFACE shouldn't
>the entire rpcproxy.h compile as C?

CINTERFACE only affects objidl.h
The entire rpcproxy header seems to be C code.

CStdStubBuffer_Release() is in the header twice.
Once as a forward reference, and the second as a macro.

The error is saying the forward reference was read as C++ for some
reason. You might check your version.

Oh, ok. Version 5 doesn't have C guards, so it is C++ when you read
the header, and C when you execute the macro.
Move the #include inside your Extern "C"

Chris Uzdavinis

unread,
Feb 15, 2007, 2:15:46 PM2/15/07
to
mae...@glue.ch (Thomas Maeder [TeamB]) writes:

>> Since this code is generated and is impossible to use correctly, it
>> is clearly a codegen bug.
>
> Are you sure that it is impossible to use it correctly? Looks like an
> POD-struct to me, so aggregate initialization should work.

Ahh, you're right. An aggregate initialization is, of course, valid.
So "impossible" was the wrong word. "Much less convenient" is a
better term.

--
Chris (TeamB);

0 new messages