Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / October 2007

Tip: Looking for answers? Try searching our database.

Errors in VC.Net porting

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dipesh_Sharma - 12 Oct 2007 05:52 GMT
Hi all,
I am porting an code written in VC++ to VC.Net to make it manage. But in
Managed VC we dont use "const" keyboard at all. but my code is using it very
frequently, so is their any alternative to it or we have to remove the
"const" keyword from our code completely. Please suggest me the solution.
Secondly i am getting one error as::
error C4439: 'function_name' : function definition with a managed type in
the signature must have a __clrcall calling convention.
code is::extern "C" __declspec(dllexport) String* APIENTRY function_name(
String* s).
Please help me out from these errors.
Thanks.
David Lowndes - 12 Oct 2007 08:22 GMT
>I am porting an code written in VC++ to VC.Net to make it manage. But in
>Managed VC we dont use "const" keyboard at all. but my code is using it very
>frequently, so is their any alternative to it or we have to remove the
>"const" keyword from our code completely.

You should still be able to use const in those parts of your code that
are still native C++, but as you've found, there's not the same notion
of const in the managed world.

BTW, you mention managed VC - if that means versions prior to VS2005,
you might be wise to move to VS2005 and use the much neater C++/CLI.

Dave
Dipesh_Sharma - 12 Oct 2007 11:24 GMT
Thanks David for this suggestion. but you have not answered my second
question :: i am getting this error ::
error C4439: 'function_name' : function definition with a managed type in
the signature must have a __clrcall calling convention.

my code is::extern "C" __declspec(dllexport) String* APIENTRY function_name(
String* s).
Please help me out from these errors.

> >I am porting an code written in VC++ to VC.Net to make it manage. But in
> >Managed VC we dont use "const" keyboard at all. but my code is using it very
[quoted text clipped - 9 lines]
>
> Dave
David Lowndes - 12 Oct 2007 12:21 GMT
>error C4439: 'function_name' : function definition with a managed type in
>the signature must have a __clrcall calling convention.
>
>my code is::extern "C" __declspec(dllexport) String* APIENTRY function_name(
>String* s).
>Please help me out from these errors.

Presumably you need to specify __clrcall. Have you tried adding it ?

Dave
David Wilkinson - 12 Oct 2007 12:31 GMT
> Thanks David for this suggestion. but you have not answered my second
> question :: i am getting this error ::
[quoted text clipped - 4 lines]
> String* s).
> Please help me out from these errors.

Dipesh:

I am not an expert on managed code, but I am sure extern "C" is not
allowed on a function with managed types in the signature.

It would appear you are trying to convert your entire application to use
managed types. If you want to do this you might as well rewrite the
whole application in C#. The big advantage of Managed C++ (or C++/CLI)
is that you can easily mix managed and unmanaged code in your
application, and you do not seem to be taking advantage of this.

IMHO, you should also take serious note of David Lowndes' suggestion to
move to VS2005. You can also use the latest beta version of VS2008
(which is free). Managed C++ as used in Vs2002 and VS2003 is obsolete,
and IMHO it would be a huge mistake to migrate existing unmanaged code
to it.

Signature

David Wilkinson
Visual C++ MVP

Dipesh_Sharma - 17 Oct 2007 09:31 GMT
HI david yes you were right that i am porting my code written in VC++ to make
it managed. I am working on VS2005, and i a not able to remove the error
c4439 of __clrcall. Please help me by providing the exact syntax of exporting
the previously written functions in VC++ to export them in VC.Net.
My code is like::extern "C" __declspec(dllexport) String* APIENTRY
function_name( String* s). And how should i mix both native & managed code in
a single project??
Thanks.

> > Thanks David for this suggestion. but you have not answered my second
> > question :: i am getting this error ::
[quoted text clipped - 21 lines]
> and IMHO it would be a huge mistake to migrate existing unmanaged code
> to it.
David Wilkinson - 17 Oct 2007 12:58 GMT
> HI david yes you were right that i am porting my code written in VC++ to make
> it managed. I am working on VS2005, and i a not able to remove the error
[quoted text clipped - 3 lines]
> function_name( String* s). And how should i mix both native & managed code in
> a single project??

Dipesh:

Maybe I am not clear what you are doing. What is String? If it is
managed and you are using VS2005, then you should be using String^, not
String*.

But my point was that in C++/CLI you do not need to convert each and
every function to managed.

To mix managed and unmanaged code you just do it (that's why it's called
IJW - It Just Works), though there are things you cannot do. I am no
expert here, but I think managed code can generally call unmanaged code,
but not vice-versa.

A good introductory book on C++/CLI is Ivor Horton's "Beginning C++ 2005."

Signature

David Wilkinson
Visual C++ MVP


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.