interop

Using a COM dll from C# without a type library

烂漫一生 提交于 2019-12-17 23:49:09
问题 I need to use a COM component (a dll) developed in Delphi ages ago. The problem is: the dll does not contain a type library... and every interop feature (eg. TlbImp) in .NET seem to rely on TLBs. The component has been used in Delphi programs here for many years without problems because "It's not much of a problem using COM objects from Delphi, because we know the interfaces" (quote Delphi developer). Is there any way I can use this DLL from c# without a TLB? I've tried using the DLL as

Is it possible to test a COM-exposed assembly from .NET?

谁说我不能喝 提交于 2019-12-17 22:44:05
问题 I have a .NET assembly which I have exposed to COM via a tlb file, and an installer which registers the tlb. I have manually checked that the installer works correctly and that COM clients can access the library. So far, so good... However, I am trying to put together some automated system tests which check that the installer is working correctly. As part of that I have automated the installation on a VM, and I now want to make some calls to the installed COM library to verify that it is

faster way to return data as an array interoping c++

烂漫一生 提交于 2019-12-17 21:34:03
问题 this is a very clean and nice solution to marsahall a struct array from unmanaged C++ code. it is allmost perfect solution when it comes to simplicity, it took me a while to get to that level of understanding the concept, so that in few lines of code, as you can see C# Main() , i have a populated array of struct ready to be 'harvested'.. typedef struct { int Id; BSTR StrVal; }Package; extern "C" __declspec(dllexport) void dodata(int requestedLength,int StringSize, Package **Packs){ int count;

Interop sending string from C# to C++

心不动则不痛 提交于 2019-12-17 21:32:19
问题 I want to send a string from C# to a function in a native C++ DLL. Here is my code: The C# side: [DllImport(@"Native3DHandler.dll", EntryPoint = "#22", CharSet = CharSet.Unicode)] private static extern void func1(byte[] path); public void func2(string path) { ASCIIEncoding encoding = new ASCIIEncoding(); byte[] arr = encoding.GetBytes(path); func1(this.something, arr); } The C++ side: void func1(char *path) { //... } What I get in the C++ side is an empty string, every time, no matter what I

COM object that has been separated from its underlying RCW can not be used - why does it happen?

[亡魂溺海] 提交于 2019-12-17 21:28:58
问题 I sometimes get the following exception: COM object that has been separated from its underlying RCW can not be used Sample code: using (AdOrganizationalUnit organizationalUnit = new AdOrganizationalUnit(ADHelper.GetDirectoryEntry(ouAdDn))) { using (AdUser user = organizationalUnit.AddUser(commonName)) { //set some properties user.Properties[key].Add(value); user.CommitChanges(); user.SetPassword(password); //it is set using Invoke //must be set after creating user user.Properties[

how can we open a word file with specific page number in c sharp?

99封情书 提交于 2019-12-17 21:16:32
问题 How can we open a word file with specific page number? This is the the code I used to open the file: public static Application Open(string fileName) { object fileNameAsObject = (object)fileName; Application wordApplication; try { wordApplication = new Application(); object readnly = false; object missing = System.Reflection.Missing.Value; wordApplication.Documents.Open(ref fileNameAsObject, ref missing, ref readnly); return wordApplication; } catch (Exception ex) { LogEntry log = new LogEntry

Paper.js Interoperability

﹥>﹥吖頭↗ 提交于 2019-12-17 20:46:35
问题 I would like to call paper.js functions from HTML buttons in my page but I believe the paper.js functions exist in their own scope. The paper.js docs mention interoperability which sounds like the right direct by then take me to a page that says "coming soon": http://paperjs.org/tutorials/getting-started/paperscript-interoperability/ Does anyone know how I can call a function created within a paper.js script from my HTML page? 回答1: Apologies for that missing tutorial. I shall really invest

Can I call a static method of a C# class from VBA via COM?

爱⌒轻易说出口 提交于 2019-12-17 20:35:59
问题 If I define a class in a C#/.NET class library, then by making it COM visible I can instantiate the class and call its methods from VBA using COM. Is there any way to call the static methods of such a class from VBA? 回答1: COM does not support static methods, and instances of COM objects do not invoke static methods. Instead, set ComVisible(false) on your static method, then make an instance method to wrap it: [ComVisible(true)] public class Foo { [ComVisible(false)] public static void Bar() {

Calling C++ function from C#, with lots of complicated input and output parameters

只愿长相守 提交于 2019-12-17 20:27:03
问题 I am new to C# but have worked extensively with C++. I have a C++ function that needs to be called from C#. After reading some answers from SO and some googling, I conclude that I need to make a pure C interface to the function. I have done this, but am still confused about how to call it from C#. The function in C++ looks like this: int processImages( std::string& inputFilePath, // An input file const std::vector<std::string>& inputListOfDirs, // Input list of dirs std::vector<InternalStruct

How do I marshal wchar_t* from C++ to C# as an out parameter or return value?

耗尽温柔 提交于 2019-12-17 19:29:07
问题 I have tried to do this in many ways, but none is working. Does anyone have a correct example for this? I just want to move the wchar_t* value from a function to the C# level. 回答1: This isn't as difficult as you think it is... What is wchar_t* ? What value does that type typically represent? A string. It's the equivalent to the LPWSTR type defined in windows.h . So, you marshal it as a string type. However, since it's an out parameter (or a return value), you'll need to use the StringBuilder