More calling DLL questions -- this time types

I have a dll that has a constructor that takes a C++ type string.
example definition in header file
        Foo(const string &filepath);

        [DllImport("FooDLL.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern IntPtr Foo(ref System.String filepath);

How do I call this in C#?  below gets me an "EntryPointNotFoundException", which indicates to me that the calling signature doesnt match....

        public IntPtr ip;
        string str = "junk";

        ip = SignumIU(ref str);


thanks!
roujeskyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jkrCommented:
You should strictly refrain from using C++-style exports in your DLL, for the simple reason being that C++ symbols are 'mangled' in order for the linker being able to process different overloads with the same name (i.e. 'Foo(int)'). See https://en.wikipedia.org/wiki/Name_mangling

So, one way to work around this would be to create a C-stly layer that wraps the C++ code and can be called using the usual P/Invoke mechanisms, e.g.

// header.h
extern "C" // ensure so name mangling will take place
__declspec(dllexport)
unsigned long CreateFoo(const char* p);
extern "C" // ensure so name mangling will take place
__declspec(dllexport)
unsigned long CallFooMethod(const unsigned long pul, int n);

// code.cpp
unsigned long CreateFoo(const char* p) {

  Foo* pf = new Foo(p);

  return (unsigned long) pf;
}

unsigned long CallSomeFooMethod(const unsigned long pul, int n) {

  Foo* pf = (Foo*) pul;

  return pf->SomeFooMethod(n);
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.