Calling Sharepoint Dlls from C++ code

 

I spent most of the nineties  in the C++ world with the venerable MFC (Microsoft Foundation Classes) , ATL(Active Template Library) & its famous smart pointers.

I recently had to answer a question in the Sharepoint newsgroups related to using Sharepoint dlls in C++:  I jumped on it as a kid in a candy store (to be honest my current candy store is Sharepoint 2010).

This is what I did:

Create a new CLR Console Application project :

 

image

The following code is generated :

 

image

Add a reference to the Microsoft.Sharepoint.dll :

 

image

 

image

Define the Microsoft.Sharepoint namespace:

 

image

Write your C++; since Sharepoint classes are managed classes, you have to use the new gcnew operator and you don’t have to call delete.

image

Run the application :

 

image

Don’t forget, Visual C++ is the only compiler that allows you to mix-up managed and native code (we call that IJW or “It just works”); and this without the overhead of the PInvoke layer.

This is quite simple, but it’s not your grandma’s C++ compiler anymore.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s