#pragma managed(push, on) and #pragma managed(push, off) in C++/CLI? - c++-cli

What is the difference between #pragma managed(push, off) and #pragma managed(push, on)?
When we need to use #pragma managed(push, on) instead of #pragma managed(push, off)?

It's obvious - "off" turns managed code off, "on" - turns it on.
We use #pragma managed(push, on) when we need to save state and turn it on.
In common case, in header file, we don't know if managed code enabled, so we enable it:
#pragma once
#pragma managed(push, on)
public ref class Foo
{
...
};
#pragma managed(pop)

Related

how to static add openssl with c++ builder?

I am able to use openssl in the source code below, but without the libeay32.dll file, my project does not open. I want to add it static and eliminate the need for dlls. How can I do that ?
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <openssl/bio.h>
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
#pragma comment(lib, "libeay32.lib")
#pragma comment(lib, "ssleay32.lib")
TForm1 *Form1;
void __fastcall TForm1::Button1Click(TObject *Sender)
{
BIO* key;
void* buf;
key=BIO_new_mem_buf(buf,100);
}
//---------------------------------------------------------------------------
I tried to compile statically but without success.

How to suppress "Auto property synthesis will not synthesize property 'xxxx' declared in protocol 'yyy "?

For debugging purposes, I am creating a class B which conforms to a certain protocol A.
#interface B: NSObject<A>
#end
Objective of this type hold internally another object _internalObj which also confirms to protocol A.
I also override some of the methods and re-route the others using:
- (void)forwardInvocation:(NSInvocation *)anInvocation
{
if ([_internalObj respondsToSelector:
[anInvocation selector]])
[anInvocation invokeWithTarget:_internalObj];
else
[super forwardInvocation:anInvocation];
}
How, I am getting the following errors/warnings (depends on my project settings) which I am not successful suppressing.
"Auto property synthesis will not synthesize property 'xxxx' declared in protocol 'yyy "
I already tried the following but it didn't help:
#pragma clang diagnostic ignored "-Wobjc-property-synthesis"
#pragma clang diagnostic ignored "-Wobjc-missing-property-synthesis"
Any ideas?
Just found -Wobjc-protocol-property-synthesis on http://fuckingclangwarnings.com and it's working.

Windows SDK - Only for DirectX-Apps?

because I habe problems installing the DirectX SDK June (11), I read that Windows 8.1 users already have the DirectX 11 SDK integrated - in the Windows-SDK. But nevertheless, I could not get the info (even not from MCs article "Where is the DirectX SDK) if this SDK only offers the possibility to write DirectX-Apps (Win 8-Apps). If it also supports writing normal desktop-programs:
Do you know how I can set up a normal Win32-Project using DirectX from the Windows-SDK.
#pragma region COM
#include <guiddef.h>
#include <OCIdl.h>
#include <Unknwn.h>
#include <Objbase.h>
#pragma comment(lib, "Ole32.lib")
#include <OleCtl.h>
#pragma comment(lib, "OleAut32.lib")
#include <comutil.h>
#ifdef _DEBUG
#pragma comment(lib, "comsuppwd.lib")
#else
#pragma comment(lib, "comsuppw.lib")
#endif
#pragma region WIC
#include <wincodecsdk.h>
#include <wincodec.h>
#pragma comment(lib, "windowscodecs.lib")
#pragma endregion
#pragma region D2D
#include <d2d1.h>
#include <d2dbasetypes.h>
#include <d2d1helper.h>
#include <d2d1_1.h>
#include <d2d1_1helper.h>
#include <d2d1_2.h>
#include <d2d1_2helper.h>
#include <d2d1effects.h>
#include <d2d1effecthelpers.h>
#include <d2d1effectauthor.h>
#pragma comment(lib, "d2d1.lib")
#pragma endregion
#pragma region DWrite
#include <dwrite.h>
#include <dwrite_1.h>
#include <dwrite_2.h>
#pragma comment(lib,"dwrite.lib")
#pragma endregion
#pragma region D3D
#include <dxgi.h>
#include <d3d11.h>
#include <d3d11_1.h>
#include <d3d11_2.h>
#include <DirectXMath.h>
#include <DirectXColors.h>
#include <DirectXCollision.h>
#include <DirectXPackedVector.h>
#pragma comment(lib, "d3d11.lib")
#pragma comment(lib, "dxgi.lib")
#ifdef _DEBUG
#include <d3dcompiler.h>
#pragma comment(lib, "d3dcompiler.lib")
#endif
#pragma endregion
#pragma region XAudio
#include <Xaudio2.h>
#include <x3daudio.h>
#pragma comment(lib, "Xaudio2.lib")
#pragma endregion
WIN32 SDK D3D + D2D + XAudio + WIC includes and static libs. Put these in your pch.h or stdafx.h after <windows.h>.
And the Desktop DirectX Graphics Reference links:
Direct3D11
Direct2D
DirectWrite
XAudio2
Of course it's possible to writing an normal Directx desktop programs with the Win8 SDK since DirectX SDK now a part of the Windows SDK, and you can build a desktop app with the Windows8 SDK just like old DirectX SDK just include your header, link your library and write your app, Just be aware that this SDK don't supports writing app to older version of DirectX (DirectX9, 10) and older it's only supports DirectX11,
If you want to writ a app to older version of DirectX then use the old one SDK

Where is the DEBUG macro defined?

When I run code such as the following:
- (void)viewDidLoad
{
#ifdef DEBUG
NSLog(#"debug");
#else
NSLog(#"here");
#endif
[super viewDidLoad];
}
I see "debug" printed in the log, but I did not define DEBUG explicitly. Where is it defined?
It is most likely defined in your Build Settings under Preprocessor Macros.
Here is an example from one of my projects

How can I conditionally declare a delegate in an interface declaration?

I have an Xcode 4 project that builds to two different targets. I've defined some constants in the build settings so I can run different code for each target like this:
#ifdef VERSION1
// do this
#else
// do that
#endif
In one version of the app, I need the main view controller to open another view controller and become its delegate, but the other version doesn't use that view controller and shouldn't compile its code or try to become its delegate. I've set up the main view controller header like this:
#ifdef VERSION2
#import "SpecialViewController.h"
#endif
#interface MainViewController : UIViewController <MPMediaPickerControllerDelegate, SpecialViewControllerDelegate> {
// etc.
The conditional around the #import tag works fine, but how can I declare this class to be the SpecialViewControllerDelegate in one version but not the other?
Just use a #define preprocessor directive to change the delegates between versions.
Here's an example for "VERSION2".
#ifdef VERSION2
#import "SpecialViewController.h"
#define ARGS PMediaPickerControllerDelegate, SpecialViewControllerDelegate
#endif
#interface MainViewController : UIViewController <ARGS>
As long as you don't assign the delegate you should be fine leaving the implementation. Your SpecialViewController in VERSION1 (if you even have a SpecialViewController in V1) will not have a delegate so its calls will go nowhere, which should lead to no side effects.
#ifdef VERSION2
specialViewController.delegate = self;
#endif
If this approach doesn't work it almost seems like you should have a different MainViewController for each target.