|
|
I have REST implemented in C#, I will need to call REST from existing C++ Legacy code.
What is the best way to do this. Please point me to some working example. URL Thank you
|
|
|
|
|
Call your C# from C++.
The Master said, 'Am I indeed possessed of knowledge? I am not knowing. But if a mean person, who appears quite empty-like, ask anything of me, I set it forth from one end to the other, and exhaust it.'
― Confucian Analects
|
|
|
|
|
Was there supposed to be a link under that message?
|
|
|
|
|
Here you go.
I respond based on the level of enthusiasm displayed.
c++ cli - Calling C# code from C++ - Stack Overflow
(I expected most to lose interest in the "call C#" part).
Then there's the "indirect" methods, like message queues, etc.
The Master said, 'Am I indeed possessed of knowledge? I am not knowing. But if a mean person, who appears quite empty-like, ask anything of me, I set it forth from one end to the other, and exhaust it.'
― Confucian Analects
modified 25-Jul-19 16:47pm.
|
|
|
|
|
Thanks Gerry, but it's the OP who needs the information, not me. I merely wondered whether you had tried to post a link and something had gone wrong.
|
|
|
|
|
Yeah, but you're the one that responded.
Frankly, I thought calling your own code would be obvious as is "Google".
The Master said, 'Am I indeed possessed of knowledge? I am not knowing. But if a mean person, who appears quite empty-like, ask anything of me, I set it forth from one end to the other, and exhaust it.'
― Confucian Analects
|
|
|
|
|
Shouldn't you be asleep still? Or are you on the easternmost tip?
|
|
|
|
|
I had a nap after supper. Now I need to get sleepy again.
The Master said, 'Am I indeed possessed of knowledge? I am not knowing. But if a mean person, who appears quite empty-like, ask anything of me, I set it forth from one end to the other, and exhaust it.'
― Confucian Analects
|
|
|
|
|
Is there any method to call C code from VC++/MFC project ?
I need to call some functions from a C project (pretty big project). If I include some files from that C project, I get some error:
precompiled header file is from a previous version of the compiler, or the precompiled header is C++ and you are using it from C (or vice versa)
moreover, I get a lot of unrecongnized types ... to modify types and functions in C project is huge work ... how can I overcome this ? Maybe you have been in the same situaton like me ...
|
|
|
|
|
Maybe that can help:
SO: Compile C files in C++ project which do not use precompiled header?[^]
Top-most answer presents some simple workarounds. If there are a lot of .c files in your project, disabling precompiled-headers solution-wide seems appropriate.
enum HumanBool { Yes, No, Maybe, Perhaps, Probably, ProbablyNot, MostLikely, MostUnlikely, HellYes, HellNo, Wtf }
|
|
|
|
|
I saw that post, I have tried all that solutions, I still have the same error ...
|
|
|
|
|
Strange. Maybe there are some leftovers from previous compilation sessions. Did you try to clean the solution and rebuild it completely? Does the error appear for all .c source files, or only for specific one(s)?
enum HumanBool { Yes, No, Maybe, Perhaps, Probably, ProbablyNot, MostLikely, MostUnlikely, HellYes, HellNo, Wtf }
|
|
|
|
|
It may possibly depend on how you are connecting the two. In general calling C functions from MFC/C++ presents no problems and works out of the box. Maybe if you showed some of the headers that you are including and the associated error messages we may be able to figure something out.
|
|
|
|
|
I have included C header and fix some errors, but I met another error:
MyDoc.obj : error LNK2019: unresolved external symbol _function1 referenced in function "public: int __thiscall CMyDoc::SomeMethod
MyDoc.obj : error LNK2019: unresolved external symbol _function2 referenced in function "public: int __thiscall CMyDoc::SomeMEthod
so, if I included xxx.c file, I got tones of errors ... if I added that file to my project, happen nothing, I mean I got the same errors ... what could be the next step ?
|
|
|
|
|
The linker errors are telling you that some file or object is missing from the build. Check where function1 and function2 are defined, and make sure that the file that contains them is included in your project..
|
|
|
|
|
Yes, I included, but I got the first error:
precompiled header file is from a previous version of the compiler, or the precompiled header is C++ and you are using it from C (or vice versa)
even if I did that settings in my VC++ app, I still have this error ...
|
|
|
|
|
You are using a previously built precompiled header so you need to force a complete rebuild of your project to ensure it is recreated with the current compiler and header files. Unfortunately most of this is guesswork as we cannot see the structure of your project(s). As I said earlier, calling C functions from C++ always works if you have the correct header and source/object files included.
|
|
|
|
|
_Flaviu wrote: ...even if I did that settings in my VC++ app What settings?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
|
That is irrelevant. You need to show us the actual details from your project. Whatever you are doing, or not doing, to cause these errors, we cannot help you without seeing some proper details.
|
|
|
|
|
It just occurred to me that you are probably suffering from C++ name mangling. You need to add the following lines to the header files of your .c code:
#ifdef __cplusplus // these lines at the beginning of the file before your definitions
extern "C" {
#endif
#ifdef __cplusplus // these lines at the end of the file after your definitions
}
#endif
|
|
|
|
|
(google-fu seems to be lacking today, and I'm certain I'm not asking or doing the right thing)
I have defined a UI in the resource editor with a Picture Control and assign a bitmap on it :
CONTROL IDB_BITMAP1,IDC_BACKGROUND_PICTURE,"Static",SS_BITMAP | SS_CENTERIMAGE,14,7,425,263
The problem is that sometimes (most of the time) the actual bitmap does not have the same size as the picture control.
Is there a way to know the actual pixel size of the Picture Control ?
Am I doing this the wrong way? or Am I forced to do this in code (get picturecontrol client size, and StretchBlt ... )?
Thanks.
I'd rather be phishing!
|
|
|
|
|
Maximilien wrote: Is there a way to know the actual pixel size of the Picture Control ?
You already set this size in the .rc file.
But if you mean the real image size... Well, first try to "play" with SS_REALSIZEIMAGE and SS_CENTERIMAGE flags.
If it won't help then try to owner-draw.
//edit: you could use GetBitmapDimensionEx function (wingdi.h) | Microsoft Docs to obtain bitmap size.
|
|
|
|
|
thanks.
will skip MFC and do it the good old way.
I'd rather be phishing!
|
|
|
|