mfc,interop,mdiRelated issues-Collection of common programming errors


  • Bret Kuhns
    c++ visual-studio-2010 mfc c++-cli
    I’m just experimenting with mixing a native C++ (that uses MFC) static lib and a C++/CLI WinForms application. When I try to include my NativeClass.h, compiling the C++/CLI app fails because it doesn’t understand AFX_EXT_CLASS used to export the class for the lib.Just to get it working, I was able to build the native lib, then remove the AFX_EXT_CLASS from the header, then build the C++/CLI linked to the native lib. The C++/CLI app will run, the dialog comes up and outputs some dummy value from

  • Jim Fell
    c++ visual-studio-2008 mfc exception-handling console-application
    I have a CExceptionHandler class that is invoked whenever my application detects a run-time exception. For example:if ( val == NULL ) {TRACE(_T(“Unexpected NULL in sequence.”));AfxThrowException( ERROR_INVALID_DATA ); }AfxThrowException is very simple:void AfxThrowException( DWORD error ) {CExceptionHandler * pException = NULL;if ( error == 0 ){error = ::GetLastError();}pException = new CExceptionHandler( error );TRACE(_T(“Warning: throwing CSerialException for error %d\n”), error);THROW(pExcep

  • AJG85
    c++ mfc multiple-inheritance
    I got some warnings by using pure virtual interfaces on some MFC CWnd derived objects through multiple inheritance. I believe it’s caused by defining the methods which need to be implemented for the message map.warning C4407: cast between different pointer to member representations, compiler may generate incorrect codeThat sounds like a bit more than a warning, more like something that might cause heap corruption. So is there another way to do something similar to below that won’t cause the MFC

  • red_rain
    c++ visual-studio-2010 mfc hunspell
    After I managed to get Hunspell working with a Win32 console application, I want to use Hunspell in an MFC application in the same solution. I get the following error when I try to compile the MFC application.spellcheck\hunspell-src\hunspell\replist.hxx(23): error C2062: type ‘const char’ unexpected spellcheck\hunspell-src\hunspell\replist.hxx(23): error C2238: unexpected token(s) preceding ‘;’Some information about the solution:The solution is called spellcheck. The Hunspell source files are lo

  • Baiyan Huang
    c++ mfc constructor
    The MFC’s root object CObject’s copy constructor and assignment are disabled by default.In MSDN, there is a descriptionThe standard C++ default class copyconstructor does a member-by-membercopy. The presence of the privateCObject copy constructor guarantees acompiler error message if the copyconstructor of your class is neededbut not available. You must thereforeprovide a copy constructor if yourclass requires this capability.In CObject’s source code, there is a comment:Disable the copy construc

  • dearvivekkumar
    visual-c++ mfc
    How can we generate event, so that the framework will invoke its message handler OnSize() function in MFC at the instance at which I need.Thanks

  • Ganesh
    windows mfc winapi processes communication
    I need a way to store a value somewhere for temporarily by say Process A. Process A can exit the after storing the value in memory. After sometime Process B comes accesses the same location of memory and read the value. I need to store in memory, because I dont want the data to persistent across reboots. But as long as the system is up, it Independent of the Process the data must be accessible. I tried MailSlots and Temporary files in windows, both seem to have problem where the process referenc

  • ahmd0
    c++ windows winapi mfc dialog
    I need to adjust the dialog window dynamically based on its size. To do so I employ the following technique:I load it up and get its size from the CDialog::OnInitDialog() handler. If the size is too big, I end the dialog by calling CDialog::EndDialog And then update global variable and reinit the dialog-derived class again with the size adjustment.What happens is that on the second pass, some APIs start acting strangely. For instance, MessageBox does not show (thus all ASSERT macros stop working

  • Alex Stamper
    c++ mfc dialog canvas
    I want to create an application which main window has canvas (or something where I can draw custom things) and some controls, like buttons and edit fields. But I got stuck about how to do it.I tried to create MFC with SDI, but how to add control to CDC..? I tried to create one dialog with buttons and edit fields, but which control refers to something I can draw at..?Please, enlighten me how to do this..

  • JToland
    c++ mfc clr unmanaged managed-c++
    I have a lot of unmanaged C++ code written quite some time ago. Now, I’m wanting to go back and add automated tests to that code using MS Test (built into Visual Studio). However, in order to do that, I either have to build the C++ as a .lib file and write a wrapper layer around it (in order to call it from C# tests) or I need to be able to compile the code as managed. The first option I’ve got worked out, but ideally I’d prefer to use the second option so that don’t need the wrapper layer. Note

  • Seth
    c# c++ interop c++-cli
    I have a mixed mode dll with native dll dependencies.I am loading the mixed mode dll from a C# exe using Assembly.Load. However, the location of the mixed mode dll is not in the application bin directory, therefore it fails because it only looks for the native C++ dll’s in the bin and the folders in the PATH environment variable.I thought using the option /assemblylinkresource was suppose to stop this and force the native dll’s to be found in the alternate directory alongside the deployed mixed

  • horgh
    c# excel windows-services interop
    I’m developing a windows service, generating a report. This report has a template. This template is prepared in an excel file. This file is copied to the output folder. While developing I launched the service like a console application and had no problems accessing this file.Then I prepared a service installer. The service is installed under Local System account. So this excel template file is marked as content and copied to the installation directory together with the executable as well. But wh

  • Peter Mortensen
    java scala interop scala-java-interop
    I am learning Scala and I have a Java project to migrate to Scala. I want to migrate it by rewriting classes one-by-one and checking that new class didn’t break the project.This Java project uses lots of java.util.List and java.util.Map. In new Scala classes I would like to use Scala’s List and Map to have good-looking Scala code.The problem is that new classes (those are wtitten in Scala) do not integrate seamelessly with existing Java code: Java needs java.util.List, Scala needs its own scala.

  • AFrieze
    java .net web-services soap interop
    I am using C# with .net 4 and am trying to consume a java webservice. My code was autogenerated by adding a .net 2.0 style webservice reference. I believe there is an issue with the types .net is sending to the java webservice, here is the exception I receive when I attempt to connect:Internal Server Error (deserialization error: deserialization error: unexpected element type: expected={http://schemas.xmlsoap.org/soap/encoding/}long, actual={http://www.w3.org/2001/XMLSchema}long)Old documentat

  • breathingdust
    windows-services interop powerpoint
    I’ve written an application to watch a folder, and whenever a PowerPoint document is dropped into it, it goes through the slides within it and generates png images of each slide. This works fine in a windows forms application but I’ve put exactly the same code in a windows service, used the same test file and it fails to open it with the following error:Error: PowerPoint could not open the file. at Microsoft.Office.Interop.PowerPoint.Presentations.Open(String FileName, MsoTriState ReadOnly, MsoT

  • systempuntoout
    c# .net com interop com+
    I need to create a .Net C# component with these two requirements:Giving an XML and an XSL path as input parameters should return an HTML string. The XSLT engine needs to be implemented using the MSXML XSLT processor *Using MSXML via COM Interop could be an option but I’ve found this scary knowledge base article on the subject that says: 815112 INFO: Use of MSXML is Not Supported in .NET Applications http://support.microsoft.com/kb/815112 MSXML uses threading models and garbage-collection mec

  • user1122909
    c# .net c#-4.0 interop c#-2.0
    There has been some mention of using 4.0 libraries from a 2.0 app, using COM interop. My requirement is slightly different in that I do not want to expose types to my 2.0 app, but I have a Diagnostics.Process.Start(….) command in the 2.0 application which until now, started an external EXE elsewhere on the local drive that had also been compiled under 2.0 framework. The external EXE has since been upgraded to using framework 4.0 and the Diagnostics.Process.Start no longer works, it seems for t

  • Mark
    c# c interop
    I’m trying to write a wrapper around a C function that expects a function pointer and arbitrary user data (void*). The function pointer I’ve figured out how to deal with using delegates, but I can’t figure out how to convert an object into a void*.I can make it a ref object instead, since that behaves like a pointer AFAIK, but when I try that I get an exception likeAn invalid VARIANT was detected during a conversion from an unmanaged VARIANT to a managed object. Passing invalid VARIANTs to the C

  • Nathan Koop
    .net exception com interop
    I am getting this exception while reading the shapes in excel sheet in c#: on code line ofif (worksheet.Shapes.Count >= iCurrentRowIndex) { }Unable to cast COM object of type’System.__ComObject’ to interface type’Microsoft.Office.Interop.Excel._Worksheet’.This operation failed because theQueryInterface call on the COMcomponent for the interface with IID'{000208D8-0000-0000-C000-000000000046}’failed due to the following error: Theapplication called an interface thatwas marshalled for a differe

  • David Neale
    c# interop ms-word
    I need to create an word document based on the template in c#. I have tags for only the paragraphs. Is there any way to replace the bullets and tables that are already available in the template based on the user input.I was able to replace the paragraph with input text using the Replace command in the Word InterOp.Need help to do the rest of the items.Replace the bullets based on the user input Fill the tables with the input valuesCode for replacing the Paragraph based on the tag:FindAndReplace(

  • Nikita Rybak
    c# winforms menu mdi
    I have a MDI container form, and some child forms that update their title bar texts themselves, independently. After the Text property is changed on the child form, the new title bar text from the child is not updated in the window list menu when the menu is opened. This is the auto-generated window list provided by .NET via the MdiWindowListItem property.The change only propagates when another event changes the window list physically (opening a new child, closing a child, switching to another c

  • Huaskar
    mdi mdichild
    I have a MDI Parent with several MDI Childs in it, and those MDI Childs are opened on runtime.I would like to know if there’s a way to go back to the previous MDI Child with only one key. Something similar to: Ctrl + Tab or Ctrl + Shift + TabBut I would like to press F7 and go to the previous MDI Child instead of pressing Ctrl + Shift + TabThanks very much for your time and help.

  • arced
    vb.net winforms forms mdi
    ok here is the scenario. 1. i’ve create a project that has 1 form named form1.exe 2. i’ve also create a project that has 1 MDI form. in this MDI Form. i’would like to call “form1.exe” act like / behave like MDI Form child. i’ve tried using this code : Public Shared Function SetParent(ByVal hWndChild As IntPtr, ByVal hWndParent As IntPtr) As IntPtr End FunctionPrivate Sub ShowNewForm(ByVal sender As Object, ByVal e As EventArgs) Handles NewToolStripMenuItem.Click, NewToolStripButton.Click, NewWin

  • user1312891
    c# .net winforms mdi
    I have a main (MDI) form and around 70 child forms which are intialized and shown in runtime. At a time maybe more than 1 child form can be shown. In each of the child forms there are button named “OK” and its event “btnOk_click(object sender, EventArgs e). There is a button in the Parent form named “Save”, if we click on it, in the runtime the activeMDI child forms event (btnOk_click) should get fired.Please help me on this issue.at present I do this issue, by using following codeswitch (Act

  • Mike Hofer
    c# .net user-interface mdi
    This sounds like it would be a simple task, but I’m running into some issues.I have some fairly straightforward code for my C# application:private void SwitchToSdi(){MainWindow mainWindow = GetMainWindow();for (int index = mainWindow.MdiChildren.Length – 1; index >= 0; index–){Form form = mainWindow.MdiChildren[index];if (!(form is MainWindow)){ form.Visible = false;form.MdiParent = null;form.Visible = true;mainWindow.MdiChildren[index] = null;}}mainWindow.IsMdiContainer =

  • Salvador
    delphi mdi sdi
    I currently have an SDI application that is build with Delphi 7, I want the final user to choose the type of interface between SDI and MDI at runtime. my question is how can I change the behavior of the application between SDI and MDI at runtime?Currently I know a couple of applications build with delphi that allow this: EMS SQL Manager and TOAD.thanks in advance.

  • Nev
    vb6 runtime scrollbar mdi
    I need to enable the MDI parent scroll bar only in some MDI child forms and disable it for other forms. I have resize code for resolution changes but for DPI changes the forms width goes beyond screen size. So I need to enable it for these forms and disable it for other forms.For Resolution ResizeX = Screen.Width / (1024 * Screen.TwipsPerPixelX) ResizeY = Screen.Height / (768 * Screen.TwipsPerPixelY)For DPI XPIXELSPERINCH = GetDeviceCaps(hdc, 88) YPIXELSPERINCH = GetDeviceCaps(hdc, 90)Is there a

  • Terry
    menu menuitem mdi powerbuilder
    Can you change a MDI window’s menu at runtime? I tried Changemenu() function but I failed in registering the menu itself. When I debug, menu shows it’s null.menu m_menu m_menu = m_base_menu // where m_base_menu is the menu object this.changemenu(m_menu)m_menu is NULL on the line..I also tried instantiating it m_menu = create menustill to no avail. Any hints?

  • Cechner
    mfc interop mdi
    I have an MFC MDI frame (CMDIFrameWnd-derived) that I am hosting inside a WPF shell application. CMainFrame uses the WM_CHILD style (I’ve unset the WM_CAPTION and FWS_ADDTOTITLE flags) and is parented to the WPF HwndHost.Everything looks OK except that when I maximize a child frame I usually get an access violation somewhere around the child frame window’s CWnd::OnMDIActivate() method. I assume the problem has to do with the CMainFrame no longer having a menu or caption or something. My questi

  • Witness Protection ID 44583292
    windows debugging dll mdi
    The minimal DLL below, which uses only the Win32 API, tries to do nothing more than create an MDI frame/client window and one child window, and destroy the frame window when the DLL unloads. The DLL crashes on Windows XP with an exception upon executing an INT x2B instruction in USER32.For testing, the DLL is simply invoked by a one-line application calling LoadLibrary(‘badcode.dll’).The crash happens inside the final “DestroyWindow(framewindowhandle)” just before the DLL finishes, after FrameW

Web site is in building