You know even though I have been programming in C# for a bit I have never touched really on interop. I really would like to learn how to interface with C++. I know C++ basics and have programmed some windows with the C++/WINAPI even. I'm trying to start small with it and just return a string but the program crashes and doesn't let me see the error info. Here are my C++ files (dll win32 project file):
The better these AI models get, the more this is going to happen. It's gonna turn into government versus government in regards to using proprietary and unavailable security research models to basically find flaws and vulnerabilities in other governments or companies systems. It's basically turning into a cybersecurity arms race.
This is actually a good thing. The better AI gets, the more restricted and expensive it's going to become, making it far less mainstream. This is good 👍
Question
sathenzar
You know even though I have been programming in C# for a bit I have never touched really on interop. I really would like to learn how to interface with C++. I know C++ basics and have programmed some windows with the C++/WINAPI even. I'm trying to start small with it and just return a string but the program crashes and doesn't let me see the error info. Here are my C++ files (dll win32 project file):
InteropTest.h
InteropTest.cpp
#include "stdafx.h" #include "InteropTest.h" extern "C" __declspec(dllexport) char * HelloFromDll() { char *result; result = "Hello from my DLL"; return result; }And finally my C# code (.net 4.5 console program):
Program.cs
class Program { [DllImport(@"InteropTest.dll")] [return:MarshalAsAttribute(UnmanagedType.LPWStr)] private static extern string HelloFromDll(); //[return:System.Runtime.InteropServices.MarshalAsAttribute(UnmanagedType.LPWStr)] static void Main(string[] args) { try { string strRetVal = HelloFromDll(); Console.WriteLine("Returned string: {0}", strRetVal); } catch { } Console.ReadLine(); } }The program fails on the dll call. It throws an accessviolationexception but hangs forever on that.
Link to comment
https://www.neowin.net/forum/topic/1137464-cc/Share on other sites
6 answers to this question
Recommended Posts