Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: C++ C++/CLI C
I have a C function without a class. its just a function in a header file.
I want to expose it as managed code, so i am creating a new C++ file which had
extern "C"
    #include "cfile.h"
public ref class managedClass
         ///// I want to expose the function from cfile.h
So i can use the managed code in C# like
var test = managedClass.functionName(,,);
Posted 29-Apr-13 13:19pm
Edited 29-Apr-13 13:32pm
Philippe Mori at 29-Apr-13 18:34pm
Not really a question. Just define a new function in your class and call the original one from the implementation possibly adjusting parameters for easier usage from .NET side.
Sergey Alexandrovich Kryukov at 29-Apr-13 18:40pm
Right. Alternatively, it would be better to move the whole function into a "ref" class, if this is possible.
Will you just put your comment as a formal answer, to close the issue?
Philippe Mori at 30-Apr-13 8:35am
The best solution depends a lot on existing code complexity (and if the code is used elsewhere). If the user has a single function then maybe P/Invoke from C# would be the best solution. If the function is very simple, rewitting it in C# might be the best choice...
Sergey Alexandrovich Kryukov at 30-Apr-13 11:12am
Sure, agree.
Marius Bancila at 30-Apr-13 7:19am
So you need to wrap the stand alone function with a member function? So what's the actual problem?

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

you only need to call the c-func in a member function. But you better do some error checking around it.
If you link the dll with "delayload" you will get some startup benefit.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Advertise | Privacy | Mobile
Web04 | 2.8.150327.1 | Last Updated 30 Apr 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100