|
Hiho and thanks for the help,
Yes you are right i try to describe my problem a little bit more precisely. I think the code will make it easier to understand. I do not have to host a UserControl i think so. I only want to Show a normal Windows.Forms.Form from a C# Sharp Assembly which is referenced in the MFC CLI application to use a Microsoft ReportViewer, reporting some stuff from the Application. Is this possible in general that way or will i have to host this form too ?
Greetings Torben
//MFC Application with CLI enabled
namespace::Formstarter ^CSharpForm = gcnew namespace::Formstarter();
CSharpForm-> SomeFormMethod();
//C# Assembly
public class Formstarter
{
public Formstarter()
{
FormToStart Started = new FormToStart()
Started.show();
}
}
//Class Form
public partial class FormToStart : Form
{
public SpliceReporter()
{
InitializeComponent();
}
//Not in the partial class
public SomeFormMethod()
{
//Do something
}
}
|
|
|
|
|
Are you sure the MFC app is finding the assembly with the
form in it OK? Are they in the same folder?
I just tried this and it worked fine for me
(note I changed both project output directories
to the same folder!):
C#
1) Created a control library project with the app wizard
2) Added a form
3) Added your Formstarter class and altered it to create my form class
C++
1) Created an MFC dialog app project with the app wizard
2) Changed settings to compile /clr
3) Added a button to the dialog, along with a button clicked handler.
4) Added a reference to the C# DLL (created above) to the project
5) Added code in the button click handler (1 line) to create a Formstarter
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks for the help again Mark. Yes you are right the same you did, works for me too. After you told me that it should work in general i was able to focuse an other things which cause that my app is not running.
I am developping on Win XP with VS 2008. The .Net Extension is written for the 2.0 Framework. On my developper system it works and no error is upcoming but if i put it on my target system Win2K SP4 Framework 2.0 with SP1 a microsoft error still occurs. When i put my .Net app and use ist from another .Net app instead of the MFC is works correctly so i think no Dlls are missing on the target pc. When i use a new MFC project instead of the old one it starting the .Net app everthing works fine too. If i put the call in the OnCreate Function of the main dialog of the MFC app i have to extend, it works also correct. But it does not work in my OnClickButton-method where it has to do. At the moment i am a little frustrated because i don´t know what to do anymore. I cannot debug the app because the only thing i get is this Microsoft Error. Anyone an idea perhaps ?
Greetings Torben
|
|
|
|
|
ToSchi98 wrote: I cannot debug the app because the only thing i get is this Microsoft Error
What's the exact error?
ToSchi98 wrote: it does not work in my OnClickButton-method where it has to do
Are you sure your click handler is getting called?
I guess getting it to run so you can debug it will help
find that out
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Ok Mark i finally found the error. Below there is code of the function which is called in the OnInit() method of the Dialog from which the call to the C# dll is triggered. So far so good. The final Software works on XP and Vista (both VS Studio 2008 installed) and "with this function". On Win2K with Framework 2.0 SP1 it doesn´t work. When i comment these method out it also works on Win2K. I don´t really know why this happens and i only get an error report i can send to MS with the hint that something crashes in the mswks dll. I did not spend attention to this method for a long time because nothing everything seems to be ok there was never a crash at this point.
Greetings Torben
PS: I am sorry but in the whole very big program inherited from a very nice guy not one line of documentation can be found
CString CSpliceCheckerDlg::GetVersionInfo()
{
CString csRet;
HMODULE hLib = AfxGetResourceHandle();
HRSRC hVersion = FindResource( hLib,
MAKEINTRESOURCE(VS_VERSION_INFO), RT_VERSION );
if (hVersion != NULL)
{
HGLOBAL hGlobal = LoadResource( hLib, hVersion );
if ( hGlobal != NULL)
{
LPVOID versionInfo = LockResource(hGlobal);
if (versionInfo != NULL)
{
DWORD vLen;
BOOL retVal;
LPVOID retbuf=NULL;
static TCHAR fileEntry[256];
VS_FIXEDFILEINFO *pFixedValue;
_stprintf(fileEntry, _T("\\"));
retVal = VerQueryValue(versionInfo,fileEntry,&retbuf,(UINT *)&vLen);
if (retVal) {
pFixedValue = (VS_FIXEDFILEINFO *)retbuf;
int i1 = pFixedValue->dwFileVersionMS;
int i2 = pFixedValue->dwFileVersionLS>>16;
int i3 = (pFixedValue->dwFileVersionLS&0xffff);
if (!i3) {
csRet.Format(_T("%d.%d"), i1, i2);
}
else {
csRet.Format(_T("%d.%d.%d"), i1, i2, i3);
}
}
}
}
UnlockResource( hGlobal );
FreeResource( hGlobal );
}
return csRet;
}
modified on Thursday, September 25, 2008 2:57 AM
|
|
|
|
|
What is that code supposed to do? It doesn't even return anything.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Try this:
CString CSpliceCheckerDlg::GetVersionInfo()
{
CString csRet;
TCHAR szAppName[MAX_PATH];
TCHAR szSubBlockName[256];
DWORD FVHandle;
UINT nSize;
BYTE *pData = 0;
::GetModuleFileName(AfxGetResourceHandle(), szAppName, sizeof(szAppName) / sizeof(TCHAR));
DWORD dwSize = ::GetFileVersionInfoSize(szAppName, &FVHandle);
if (dwSize)
{
pData = new BYTE[dwSize];
if (::GetFileVersionInfo(szAppName, FVHandle, dwSize, pData))
{
VS_FIXEDFILEINFO *pFixedFileInfo;
_tcscpy_s(szSubBlockName,_T("\\"));
if (::VerQueryValue(pData, szSubBlockName, (void **)&pFixedFileInfo, &nSize))
{
int i1 = (pFixedFileInfo->dwFileVersionMS >> 16) & 0xFFFF;
int i2 = pFixedFileInfo->dwFileVersionMS & 0xFFFF;
int i3 = (pFixedFileInfo->dwFileVersionLS >> 16) & 0xFFFF;
int i4 = pFixedFileInfo->dwFileVersionLS & 0xFFFF;
csRet.Format(_T("%d.%d.%d.%d"), i1, i2, i3, i4);
}
}
delete[] pData;
}
return csRet;
}
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi Mark
I tested the code you posted above an it works fine. The code you posted seems clearly to me and i think i understand the problem of the old method in general (not exactly the point of error) which was used before but this bug was very very hard to find for me because i did not search on the right place for a long time . i do not exactly know why this error occurs at the point when the .net app was started and why it does not occur with a normal .net form without any reportform. I would have expected this error when initialize this mfc dialog. However a big "thank you" from my side for the help and time you spent.
Greetings Torben
Edit: Sry i forgot the return value and the last bracket in my i postet before. Changed it.
|
|
|
|
|
Hi all,
How to create a C# control (using VC# 2008 .Net) which can be used in any language (mainly in VC++ 2008 .Net)?
Please guide me.
I appreciate any and all comments and suggestions.
Thanks in advance.
Regards,
Aniket A. Salunkhe
|
|
|
|
|
What is a C# control?
If you build a library using C#, then all public classes in
that library can be consumed by any of the .NET languages.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi,
Thanks for reply.
Mark Salsbery wrote: consumed by any of the .NET languages.
I want to add my 'Windows Form Control Library' (i.e. VC#.Net 2008 ActiveX Control) in my MFC Application of VC++.Net 2008.
Thanks & Regards,
Aniket A. Salunkhe
|
|
|
|
|
Aniket Salunkhe wrote: i.e. VC#.Net 2008 ActiveX Control
I don't know about ActiveX controls, but an ActiveX control
written in c# should work just like any other ActiveX control...
that's what they're designed to do
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi,
Is there any way to design '.ocx' in VC#.net?
Because I can't register '.dll' VC# activeX control.
Thanks & Best Regards,
Aniket A. Salunkhe
|
|
|
|
|
Hi all,
I found something to work with MFC application,
http://msdn.microsoft.com/en-us/library/b1kyh79x.aspx[^]
Thanks for your support too.
Now I am trying to integrate it with my MFC Application & Control, as I want to add mutiple control dynamically in MFC Dialog.
But I appreciate any other better suggestions.
Thanks & Best Regards,
Aniket A. Salunkhe
|
|
|
|
|
I guess I'm confused - do you need an ActiveX control or a
Windows Forms control?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: ActiveX control or a
Windows Forms control
What is difference between these 2?
I want to create a UserControl in C#. eg Analog Clock Control in C# with some properties.
|
|
|
|
|
|
Any control you create in C#, or even VB.NET, can be used by the other .NET languages. You have to add a reference to the .dll containing your control.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
Hi,
Thanks to you both for reply.
Paul Conrad wrote: can be used by the other .NET languages
I am using VC++.Net 2008, but I am doing MFC Application.
Paul Conrad wrote: add a reference to the .dll containing your control
How to add reference to .dll in MFC Application using VC++.Net 2008?
And even after adding reference in MFC Application, how to add/use custom ActiveX Control?
Scenario is,
ActiveX Control in VC#.Net 2008 as 'Windows Form Control Library'.
Application in VC++.Net 2008 as 'MFC Application' (as I am doing DirectShow programming in it).
When I try to add my ActiveX Control through 'Insert ActiveX Control', it doesn't show it in that list.
When I try to register the control using 'regsvr32.exe' it shows error as, DllRegisterServer Failed
Thanks & Regards,
Aniket A. Salunkhe
modified on Friday, September 19, 2008 3:32 AM
|
|
|
|
|
Aniket Salunkhe wrote:
How to add reference to .dll in MFC Application using VC++.Net 2008?
And even after adding reference in MFC Application, how to add/use custom ActiveX Control?
That's really fun. I suggest you google that one, it's involved and there's articles how to achieve it.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
Loading a managed C++ dll from a non-managed executable works as expected when it is loaded from a local directory. However, when loading the same dll from the same executable over a network path a FileLoadException is thrown: "Failed to grant minimum premission requests". Is there a way to decrease the DLL's security or must the computer's settings be changed in order for things to work correctly?
Thanks!
Doug
|
|
|
|
|
As far as I know you can do this through the manifest file.
Scott Dorman Microsoft® MVP - Visual C# | MCPD
President - Tampa Bay IASA
[ Blog][ Articles][ Forum Guidelines] Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
|
|
|
|
|
The managed C++ dll is strongly named and the C++ program has a reference to it. I thought that should take care of any such issues. What else do I have to do?
Doug
|
|
|
|
|
I don't think strong naming it is enough. That will help the load time and allow you to register it in the GAC, but it doesn't affect the security policies about running from a network location. There is something you can add to the manifest file which says that it's safe to run from a network location, I just don't remember what it is offhand.
You can also try using fuslogvw (http://msdn.microsoft.com/en-us/library/e74a18c4.aspx[^]) to help identify what the loader is trying to do.
There is also some information here[^] that might help.
Scott Dorman Microsoft® MVP - Visual C# | MCPD
President - Tampa Bay IASA
[ Blog][ Articles][ Forum Guidelines] Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
|
|
|
|
|
I have some unmanaged code that invokes a callback function to display a series of bit map images in a picturebox in a managed GUI.
The unmanaged code is called from a worker thread, it loops, creating the bitmap images and passing the image address and a serial number as parameters to the callback routine. When all the images have been displayed the unmanaged code finishes, and the worker thread terminates.
The callback routine copies the bitmap to a stream and uses invoke to get the gui to display the image.
The images are set to display at 1/second.
I thought I had everything working nicely, but after about 30 seconds everything dies and a 'Buffer Overrun' message is generated.
The error is generated when/in/by calling the callback routine. If I don't invoke the callback all is ok. If I invoke the call back but do nothing except return immediately everything still goes wrong after about 30 seconds.
If I make the delay 10 sec everything runs happily for about 100 seconds, but then dies again.
I've reduced the code to a simple skeleton, but still get the crash.
The unmanaged code is called using a delegate, GCHandle, and Marshall::GetFunctionPointer.
I suspect something to do with garbage collection, or the lifetime of a thread, but I'm tearing my hasir out over this.
Can anyone suggest what I may have overlooked?
Bob Swan
|
|
|
|