You might read this information from MSDN: Interoperation with Unmanaged Code[^] Also, here's more: Interoperability in Managed Extensions for C++[^] Interop is a complex subject. It kind of depends on what exactly you want to Interop with. Is this a compiled DLL? A COM type library? Or, just a bunch of text source code? Most importantly are the data types compatible? If it was me, I'd just rewrite everything in .NET framework.
ursus zeta
Posts
-
Calling managed code from unmanaged C++ -
stroe windows form as a bitmap file??Richard, I'm surprised that no one responded to this question. It is definitely possible to save a screen display to the bitmap format, as you are probably aware, most games have this capability built in. There is an article right here on CodeProject that demonstrates this: Screen and Form Capture with Managed C++[^] You may find that this is not the best possible solution, for a number of reasons. But, if it is adequate for your needs, who cares, it's simple and straightforward.
-
Trouble with writing dll[Message Deleted]
-
Trouble with writing dll...For those of you who are interested, this inquiry reaches a dramatic conclusion over at the Microsoft Technical Forums. I'm just SO HAPPY that I didn't make a TOTAL ASS out of myself, by attempting to offer some advice about something,...WELL, OK, BYE,... cgraus[^] And, More Analysis[^] -- modified at 19:29 Tuesday 13th September, 2005
-
FileLoadExceptionShow us the code for the wrapper. That's probably where your problem is.
-
Call dll problemIn the C++ .NET Framework you don't import functions from a DLL like you do in Win32; the syntax is different. The correct method is to use the DllImport attribute, which is located in: System::Runtime::InteropServices. Using the DllImport Attribute[^]
-
C++/CLI linked with win32 dll's in C# (msvs2005)I read what the responses were over at MS Technical Forums. I was on the wrong track with my last question. In Visual C++ .NET you reference another .NET assembly by inserting the #using directive in your source code. You also, as you now know, must set the LIBPATH variable that the compiler uses to search for your associated .NET assemblies. This can be done very simply by opening the Property pages for your Project (from the Solution Explorer). The following MSDN information will explain this: The Using Directive[^] And, you might want to read this, it describes how to set the path of directories that Visual Studio looks in for project files and Dlls. VC++ Directories, Projects, and Options Dialog Box[^] Referencing an unmanaged Win32 DLL is different. You must use Interop. Consuming Unmanaged DLL Functions[^] A better solutuion would be to use the Type Library Importer to convert your Win32 DLLs to assemblies, which can then be used in a managed project as if they were .NET assemblies. Type Library Importer[^]
-
C++/CLI linked with win32 dll's in C# (msvs2005)Hi _eulogy_, I ran across your post over on the Microsoft Technical Forums. Pretty interesting stuff,...that left me thoroughly mystified. Does your SceneViewer code derive from the IDesignerHost interface? Given the sophistication of your project, I can't imagine that Visual Studio can't find your DLLs (this is TOO simple an error, and you obviously know your way around the compiler). I've noticed that sometimes (and this happens to me all the time), if you create multiple intersecting errors that don't conform to the compiler's internal diagnotic logic, it will issue an error message, but that message will be misleading.
-
How to parse an XML file as a test case to a CPPUNITI had to google CPPUNIT to find out what it was. It would be better if you would post the actual code so we can see what you are doing. The System::Xml namesapce has a number of well-developed classes that can used to read XML data into memory. The most obvious is: XmlReader. But, in your case, (I'm guessing here) you might prefer XmlDocument or the Navigator object that be created for XmlDocument. Read the documentation; these classes are easy to use and almost foolproof.
-
Linkage in c++The notion of linkage is kind of complicated because the word describes code properties that can be understood within several different contexts. The most obvious is referring to the compiling process when the LINKER is invoked to supply code linking the object files in your project to another existing external binary Library (typically a DLL) of funtions and resources. Another distinct context for the term 'linkage' involves the using terms like 'extern' preceeding function prototypes being imported via P/Invoke, or Interop, (unmanaged code being inserted into a managed environment). This merely prevents the Visual Studio compiler from managling the name of the function. This is referred to as 'specifying linkage'. I frankly hate the language that Microsoft engineers use to describe their technologies. It can be, and often is, confusing as hell. I suggest you be more specific about the context in which the term is being used. In this case, I have described only two of possibly a dozen or more conventional usages. But, generally speaking, internal linkage is similar to execution scope, and external linkage refers to separate compiled binary entities and dependencies in other programming languages or compiled by other vendor compilers. You might find this article helpful: Mixed Language Programming and External Linkage[^]
-
.resX file question??I've been reading about this recently in Chris Sells book, "Windows Forms Programming in C#". He has a 30 page chapter on the subject in which he describes in detail how to embed resources into a .NET Framework executable. The process is a little different in C++, and. in all probability, depends on which version Visual Studio .NET you are using. If you haven't tried it already, what happens when you open the compiled executable in Ildasm.exe? The manifest should show your resources and the associated namespaces. This is from Chris's book: "To check that a file has been embedded properly into your project's output assembly, you can use the .NET Framework SDK tool ildasm.exe. This tool shows all embedded resources in the Manifest view of your assembly". Depending on the method that you used to embed the resource, he goes on to describe the process that Visual Studio .NET uses to assign the default namespace and the actual path to the resource. He also points out that building your project causes the .resx data to be embedded as nested resources, which are resources grouped into a named container. He then goes on to describe several methods for loading these resources. You don't say in your post, but, how are you attempting to access these resources?
-
how to write an avi fileDirectShow has a number of APIs desined specifically for this purpose. You'll find that it's not really a simple, intuitive process, though. If you can locate the SDK tools that come with the DirectX SDK, there should be one known as: GraphEdit.exe Using DirectShow[^]
-
ActiveX control - visual C++It's actually alot easier than you would suspect. There is a utility that is included with the .NET Framework SDK, called: AxImp.exe This converts your ActiveX control into a .NET assembly.
-
mc++ icons/resourcesI too has similar problems tring to embed image resources into a .NET assembly. I have the standard 2003 version of Visual C++ .NET, and in the documentation they tell you put the Icon or image file into the same directory as the executable. This works, but, as you have noted, is prone to user error. The Chris Sells book: "Windows Forms Programming in C#", he describes in great detail several methods for embedding image resources into the binary. These methods do not work in Visual C++ .NET. I did, however, find this information from a sample chapter of a book by Richard Grimes, "Developing Applications with Visual Studio.NET". 8.3.4 Managed C++ and Resources Managed C++ projects allow you to add resources through the Solution Explorer or Class View window, but these will be Win32 resources. If you want to add your own .NET resources, you need to edit the project settings. Here are the steps: First you need to add an XML file to your project. To do this you should use the Add New Item dialog of Solution Explorer, and ensure that the extension of the file is .resx (the resgen utility insists that XML resource files have this extension). If you forget to give the file this extension, you will have to remove the file from the project, rename it using Windows Explorer, and add the renamed file to the project with Add Existing Item from the C++ Solution Explorer context menu. The reason is that the C++ Solution Explorer (unlike the C# Solution Explorer) does not allow you to rename a file that has been added to a project. Once you have added the .resx file to the project, you should add the bare minimum of resource file contents: the node and the three nodes I mentioned earlier: ResMimeType, Reader, and Writer. After that it makes sense to add at least one node (essentially as a template), and then you can edit the resource file using the XML designer. The next task is to add the .resx file to the build. To do this you should select properties of this file from the Solution Explorer context menu by selecting General Configuration Properties and making sure that the Tool property option selected is Custom Build Tool. You can then set the tools command line through the Custom Build Step option (Table 8.2). Table 8.2 Custom Build Step properties for an .resx file Property Value Command Line resgen $(InputFileName) $(OutDir)\$(InputName).resources Description Building .NET resources Outputs $(OutDir)\$(InputName).resources Choosing Custom Build Step will a
-
using a MFC DLL in C++ .NetSorry for not replying. I'm not a big fan of MFC, but, I've read that using MFC classes in a .NET CLR project can be problematic. As I recall there is a conflict with a compiler switch that enables runtime type checks in MFC, and this conflicts with the operation of the Common Language Runtime. Sorry for my previous post, it could just be making things more difficult for you. There is an article on MSDN Magazine about this problem. I suggest that you search there.
-
using a MFC DLL in C++ .NetThat unresolved external symbol is pretty common; and generally, it means that you somehow failed to reference whatever it was (DLL), or failed to link to the LIB file. In this case, since you are importing an unmanaged function into a managed .NET project, you must use the System::Runtime::InteropServices namespace and the DLLImport attribute preceeding the function declaration. This explains and shows the correct syntax: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemruntimeinteropservicesdllimportattributeclasstopic.asp[^]
-
help needed adding com components with idlYou should provide more information along with your inquiry. Anyone responding will have to ask you a number of questions. I assume that you are new to this kind of thing. If the COM component has a type library, the easiest thing to do is to convert it to a .NET assembly with the utility, TlbImp.exe. If you don't understand that clearly, then you should read up a little on COM Interop; COM components are unmanaged and you are trying to use it in a managed app.
-
axWebBrowser in MC++If you are getting an Interop error saying that the namespace does not exist, it's because Visual Studio .NET can not find the generated assembly. Where is it? You can put it in your project directory, this is a default Visual Studio search location. You can also set the search path by right clicking on the project in the Solution Explorer and setting the path in the appropriate property page. Read this from MSDN: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vsintro7/html/vxurfVCDirectoriesProjectsOptionsDialogBox.asp[^] You want to set the path for the reference files. You must select this from the dropdown menu (the default is the #include directory). Also, Adam Nathan does exactly what you are doing in his book, ".NET and COM: The Complete Interoperability Guide"; he provides all the code and an very clear explanation about how and why you are doing what you are doing. If you are new to this kind of thing, I would recommend reading the book, it's excellent.
-
How to wrapp Friend function in managed c++?Seems like I read somewhere that friend functions are not allowed in managed classes. Constraints: A __gc class shall not declare or define friend classes or functions. Read this: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmxspec/html/vcManagedExtensionsSpec_4.asp[^]
-
ArrayRead this at MSDN: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmxspec/html/vcManagedExtensionsSpec_4_5.asp[^] Array syntax is a little different in the .NET Framework, than it is in just plain old Win32 Visual C++. The __gc array is declared first with the new operator; optionally, with an integer for the size of the array (although this can be altered, arrays are dynamic). After creating the array, you then initialize it using the element member index. It's pretty simple, really.