Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to use Managed DLL in Unmanaged DLL and vice versa...

422 views
Skip to first unread message

Arif

unread,
Jan 8, 2010, 2:44:48 PM1/8/10
to
Hi All,
I was tring to create some dialogs with basic windows
controls like tabs,checkbox, picture control, buttons, URL links
etc....

I discovered that's it's very time copnsuming doing it pure Win32
way ... then I thought of exploring other technology/apps...

Delphi/ MFC/.NET

I discovered creating forms using .NET is very easy it's almost like
VB...where you just design what you want and code gets generated.....

In VS2008 I created a New Project-> Visual C++-> CLR ->Windows Form
Application .... and it worked fine

Now I wanted to create a ..NET DLL which would hold my all
dialogs ...provide some exported helper functions to invoke them from
pure Win32 Application or DLL

I created New Project-> Visual C++-> CLR ->Windows Form Control
Library.....

which does generate a DLL ...but I am not able to export any
function from this DLL
when I try to export any function

I get following two error

error C3389: __declspec(dllexport) cannot be used with /clr:pure or /
clr:safe
error C3395: 'myfunction' : __declspec(dllexport) cannot be applied to
a function with the __clrcall calling convention


how do i get of rid of this i went to propject properties and tried if
i could remove those flag /clr:pure and /clr:safe
but i could not find any option there....


I also want to used some exported structure ( which contain only
member variable and no functions)
of Win32 DLL...

This was first time ever i used .NET ..
Any URLs to learn how to do what i want to do , would be really
helpful....

Thanking you all in advance
-Arif

David Lowndes

unread,
Jan 9, 2010, 8:20:20 AM1/9/10
to
> I was tring to create some dialogs with basic windows
>controls like tabs,checkbox, picture control, buttons, URL links
>etc....
>
>I discovered that's it's very time copnsuming doing it pure Win32
>way

All the things you mention should be fairly straightforward to do with
the Win32 dialog editor, however...

>Now I wanted to create a ..NET DLL which would hold my all
>dialogs ...provide some exported helper functions to invoke them from
>pure Win32 Application or DLL
>
>I created New Project-> Visual C++-> CLR ->Windows Form Control
>Library.....

I think most people would recommend that you probably choose C# for a
.Net project - things in the IDE just work easily with it.

>which does generate a DLL ...but I am not able to export any
>function from this DLL
>when I try to export any function
>
>I get following two error
>
>error C3389: __declspec(dllexport) cannot be used with /clr:pure or /
>clr:safe
>error C3395: 'myfunction' : __declspec(dllexport) cannot be applied to
>a function with the __clrcall calling convention

Since you're creating a .Net module you'd probably find it easier to
interface using .Net techniques and have your Visual C++/CLI program
interface to it that way.

Dave

Arif

unread,
Jan 15, 2010, 3:01:58 PM1/15/10
to
Thanks dave....
I converted my Win32 dll written in C++ to .net using /clr switch....

I added the tnew forms (I think It's same as you do form C#) ....

but now my problem was I wanted to use some Win32 DLLs written in C+
+..

I chose to use p?Invoke for it....
I am successfully able to invoke functions in Win32 DLL....

but now I am facing problem with Types....

I called following three native functions in my managed code

int function1(void);
bool function2(void);
wchar_t *function3(void);


when using the function1 , i am getting correct return value ...but
when using function2... I am always getting return value as true... i
had put a break point in function2 and i see that when it returns
false ...even then ...in managed code it is received as ... .true....

and about function3, that's also not working if I am returning say
L"Test"
and in managed code when i received it as String^ i just get "T"...


this how i have delcared native functions mentioned above in my
managed code

[System::Runtime::InteropServices::DllImportAttribute
("SystemHook.dll")]
static bool function2(void);

[System::Runtime::InteropServices::DllImportAttribute
("SystemHook.dll")]
static int function1(void);

[System::Runtime::InteropServices::DllImportAttribute
("SystemHook.dll")]
static String^ function3(void);


and this is how I am using them...

Boolean result = function2(); // here it self i can
see result is always true....
int iRes = function1();
this->checkBox6->Checked =result;

this->Text = function3(); //setting the
dialog's title

David Lowndes

unread,
Jan 24, 2010, 6:17:04 PM1/24/10
to
>I converted my Win32 dll written in C++ to .net using /clr switch....
>
>I added the tnew forms (I think It's same as you do form C#) ....
>
>but now my problem was I wanted to use some Win32 DLLs written in C+
>+..
>
>I chose to use p?Invoke for it....

There's no need to use PInvoke with C++/CLI - just do it as though it
was pure C++/Windows, it just works! That's the beauty of C++/CLI in
the managed world over the other .Net languages.

I've never used PInvoke so I don't know if you have anything wrong
there.

Dave

0 new messages