Share via


Error MIDL2311 : statements outside library block are illegal in mktyplib compatability mode

Question

Tuesday, September 8, 2015 10:49 AM

Hi,

With VC12 and Win 10.0A SDK we are getting the following error:

error MIDL2311 : statements outside library block are illegal in mktyplib compatability mode : [ ]

This issue was not seen with “VC12 and SDK 7.1A” and “VC9 and SDK 7.0”

Apart from  the below two solutions is there any solution available

1. Do not use the /mktyplib203 switch unless you have to deal with legacy code dating back to mktyplib ver.2.03.

2.  In the .odl file, put the following inside the library block:

     #include <olectl.h>

Note: We have many odl files to be modified.

Thanks in advance.

All replies (5)

Wednesday, September 9, 2015 3:14 AM

Hi GeethaPriya Balaraman,

Please check below kb article and try the fourth solution if it helps. The fourth solution may not need to modified the odl files.

https://support.microsoft.com/en-us/kb/243219

I copy it here.

In the SDK Olectl.h file, move the section with #pragma once inside the part of the file invisible to MIDL or mktyplib.

 The SDK olectl.h file looks like this:


#ifndef _OLECTL_H_
#define _OLECTL_H_

#if _MSC_VER > 1000
#pragma once
#endif

#if !defined(__MKTYPLIB__) && !defined(__midl)
// most of the file
#endif  

// some  #defines
#endif
                        

 Change it to:

#ifndef _OLECTL_H_
#define _OLECTL_H_

#if !defined(__MKTYPLIB__) && !defined(__midl)

#if _MSC_VER > 1000
#pragma once
#endif

// most of the file
#endif  

// some  #defines
#endif

Best regards,

Shu

We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.


Wednesday, September 9, 2015 3:35 AM

Hi Shu,

Thanks for the quick response.

We have checked the olectl.h under \WIN_SDK_10.0A\Include\OleCtl.h. The changes as per solution:4 is already available in the file.

Please find the snippet below:

#ifndef _OLECTL_H_

#define _OLECTL_H_

#if !defined(__MKTYPLIB__) && !defined(__midl)

#if _MSC_VER > 1000

#pragma once

#endif

#if !defined(RC_INVOKED)

#include <pshpack8.h>

#endif

#include <ocidl.h>

Thanks


Thursday, September 10, 2015 10:24 AM

How do you use windows 10 SDK with VS 2012? It is better to use VS 2015 with windows 10 SDK.

I suggest you don't use  /mktyplib203. Try go to project properties -> MIDL->MkTypeLib Compatible

-> No.

If you still get this error, it is better to post the part of your IDL code that causes the error here. If possible, please create a simple sample to reproduce this issue and post the reproduce steps here.

We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.


Friday, September 11, 2015 9:10 AM

Thanks for the response and suggestions.

As we do not have the dependent  OTS in VS 2015, thus we are porting to VS2013 with windows 10 SDK.

(We will be running our application in Windows 10 OS)  .

Is there any issues with this combination?


Tuesday, September 15, 2015 12:40 PM

Is there any issues with this combination?

It may save you a bit of trouble to  build against Windows 10 SDK with Visual Studio 2013. Check this blog:  Windows 10 SDK RTM

"VS 2013 Users: As with the past few releases, the Windows 10 SDK only integrates with the latest Visual Studio, VS 2015. You can use the Windows 10 SDK with VS 2013 by using the props attached per this Visual C+ Team Blog."

By the way, do you have any update for the original issue? Any reproduce steps?

We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.