|
You do know that managed extensions has been deprecated for quite some time, and it's now C++/CLI, right?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
You can do a lot worse than Nish's book, C++/CLI in action (see http://www.manning.com/sivakumar/[^] ). I found it a really good introduction to one of the better things to come out of Microsoft in recent years, C++/CLI. Highly recommended.
modified on Tuesday, July 5, 2011 4:33 AM
|
|
|
|
|
|
This maybe a common question, and maybe there are many articles and threads talking about the mixed coding.
But all the mixed coding seems prefer to using #pragram unmanaged/managed, and using dll import, something like this. I plan to make a winform program, and when I press some button, the program can call the unmanged function. So in that case, I should call the unamaged function in button click event, like this:
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
// call the unmanaged function
CallUnmanaged();
}
However, I had compile error: 'CallUnmanaged': identifier not found. I tried to use extern the unmanged function in the managed codes, there are still many errors.
Anyone can tell me how to fix this without using dll import? just simpile function call. Thanks.
Best wishes
Joul
|
|
|
|
|
You must tell the compiler where to find the function typically by adding the appropriate include directive... or you somehow have to declare the function somewhere.
Is CallUnmanaged in another DLL? Is so, you have to properly export/import the function. If the function is in the same DLL then a simple declaration will do.
Typically function are declared in header files and header files then be included to use that function. If the function is uses across DLL, then it must be exported/imported as otherwise it would be visible from outside the original DLL.
Importing manged code is easier as we only have to add a reference to the DLL. For unmanaged function though, they mus be made visible to the compiler before being used by either including the file with the declaration or duplicating the declaration (normally not recommanded).
Philippe Mori
|
|
|
|
|
Thanks Mori, the CallUnmanaged function is defined by another .cpp native file of the project solution. That's I just want to call the CallUnmanaged function without through DLL. The compiler doesn't know the native function, that's the key problem. Maybe this is a simple question.
Joul
|
|
|
|
|
Well, generally all functions in a .cpp that are intended to be used from other files in the project should also be declared in the corresponding header. Then in the file where you want to call the unmanaged function, you just include that file.
In fact, this is the same for managed functions inside the project or any functions in standard librairies.
For this aspect C+/CLI works exactly as C++. The main difference with standard C++ is that when you add a reference to a managed DLL, all public symbols will be visible without any additionnal include to all file in that project. So for managed code outside the current project, C++/CLI behave more like C#.
ProjectA
unmanaged.h
void UnmanagedFunction();
unmanaged.cpp
#include "unmanaged.h"
void UnmanagedFunction()
{
}
other.cpp
#include "unmanaged.h"
void CallingFunction()
{
UnmanagedFunction();
}
Philippe Mori
|
|
|
|
|
Hi Mori,
Thanks for your kind help, I got your meanings and solved the problem. Many thanks
BW
Joul
|
|
|
|
|
I build an app w/VC++6. I design a window with an EDIT CONTROL (IDD_MYEDIT) , associate a CEdit control (m_myedit ). I switched on the PASSWORD style of the control.
Can be triggered this style on or off during the program running?
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
After the edit control has been created, the ES_PASSWORD style can't be changed.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
i have an c++ application build with /clr option and have integrated crash reporting feature.
the crash dump it generates does not show line numbers when i debug the dump using windbg.
(i found that applications build with clr does not show line numbers)
it shows the function name where it crashed but not the exact line number. for eg
it shows:
03434456 02312434 CExApp::OnOpenFile() + 0x30c
Is there any way to calculate the line number by using the offset 0x30c ?
thanks
|
|
|
|
|
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Please use <PRE> tags for code snippets, they improve readability. CP Vanity has been updated to V2.4
|
|
|
|
|
I am beginner in visual studio 2008 (C++/CLI) (Windows Form Application).
Can anyone help me Please..?
I want to know that how we can create multi-project solution in following way?
for example..
I have two projects "A" and "B".
can form of "B" called from "A"'s click event?
Thanks in advance.
|
|
|
|
|
If the two projects create executables, then you'll need some form of Interprocess Communication[^] for the two processes to communicate.
Or is one or more of the projects a library?
What are you trying to do?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks for your quick reply
I am studying the Interprocess Communication link that you suggested to me.
Neither the projects are any type of library
The scenario is as:
Our company have too many (more than 20 in numbers) products (Hardware units) needs separate UI to handle Inputs and Outputs.
1. It is difficult to handle different software application for each product.
2. If customer has more than one products of our company then he should be able to select dynamically which application will run.
so I am trying to integrate all the needed and related applications in one solution.
|
|
|
|
|
If you just have a main solution (creating an executable) and all you're trying to do is spawn other applications when a users selects something within the main app, then its easy, all you have to do is know how to start the secondary application.
|
|
|
|
|
If projects are managed DLL, then you could do anything you want. The only thing to be aware is that reference to others DLL are unidirectionnal.
Assuming that each project are independant of the other, you could then have:
- ProjectA.dll (managed DLL with forms for A)
- ProjectB.dll (managed DLL with forms for B)
- ProjectC.dll (managed DLL with forms for C)
- MainApplication.exe (main application with reference to other DLLs)
MainApplication will then be able to uses any public forms in other DLLs. It will be able to uses events generated by those forms.
You may also need to add an extra DLL that will be referenced by each project if you need some common functionality.
By the way, then main application I have developped has many C++/CLI and many C# DLL.
I prefer to uses C# for the UI as design-time support is far superior. The main problem with that is that when refactoring code, sometimes, I have to convert some C++/CLI code to C# and vice-versa. I was using .NET Reflector with C++/CLI plug-in but now the new version is a paid product and old plug-in does not seems to be supported.
Philippe Mori
|
|
|
|
|
I have prepeared project folllowing instrctions given in this article(Calling Managed .NET C# COM Objects from Unmanaged C++ Code).
I have used VS 2008 and .Net Framework 2.0 for both projects.
I am able to access ShowDialog() method as shown in this article but when i added another method to same interface it was not available in c++.
I checked both .tlb and .tlh file I can see both of them having declaration of new method added.
but I try to acces it through pDotNetCOMPtr-><new method="" not="" included="">
Please let me know what I am missing?
|
|
|
|
|
Did you rebuild the .NET project?
Also, it helps if you could show the code.
|
|
|
|
|
By the way, you might also consider making a mixed-mode C++ code. If you cannot put your original C++ code in that project without problems, you might then explore the possibility to create a mixed-mode layer.
In my case, my C++ code is compiled in mixed mode (/clr) so I can mix regular C++ with managed C++ in the same DLL. It might not always be feasible in existing code is large and uses incompatible options.
In that latter case, I might also try to have an extra DLL (mixed-mode C++) that would make the bridge between unmanaged C++ and managed code. Then existing C++ code would uses that DLL to indirectly call C# code.
This approch have some advantage like you could somehow adapt C++ code to be easier to uses or follows your C++ code convention or do some transformation between types like converting System::String^ to wstring for uses in C++.
I have never really tried the C# COM objects by their should be no problem with that method provided that all required symbols are public and GUID are assigned when required.
Philippe Mori
|
|
|
|
|
Hi all,
I wanna to connect postgresql, and I prefer to ODBC with MFC before.
However, I don't know how to do this by c++/cli, can any kind man give me some advice or some online ariticle about this?
Thanks in advance.
Joul
|
|
|
|
|
|
Hi,
I wanna to draw something in the panel which can be scrolled.
For example, I just want to draw a line in the panel, so I added the drawing codes in the on_paint event:
e->Graphics->DrawLine(bluePen, 0, 0, 100, 100);
And then it can be displayed correctly.
However, when I scrolled the vertical scroll bar, it can display ok, but sometimes display with remnant. I don't know whether it's a bug of the panel control.
So I tried to add "Invalidate" function to the panel scroll event, however, the panel can not display ok when scrolling.
Can any kind man give me some advice? Maybe it's a simple question.
Thanks.
Joul
|
|
|
|
|
hi, all.
I found the reason, just add AutoScrollPosition when drawing.
Joul
|
|
|
|
|
Hey Guys,
I've done some Googling and some MSDN searches, but no luck. What I have is two Windows forms. I want to be able to attach a file/files from one of the forms, and then have the other form be able to see/open these attachments. Any ideas on which controls, data structures, or methods to use? I'm a bit stumped right now. I've investigated the FileDialog class, but I don't think that's what I need.
[Insert Witty Sig Here]
|
|
|
|