dllimport

How do I handle a failed DllImport?

你离开我真会死。 提交于 2019-12-30 10:10:31
问题 I'm attempting to write a C# managed class to wrap SHGetKnownFolderPath, so far it works on Vista, but crashes on XP due to not finding the proper function in shell32.dll, as expected. I want to have it set so I can fallback on a (admittedly hacky) solution using System.Environment.GetFolderPath if using XP. (Or, even better, if it can't find the funciton in shell32.) Is there any way to do this other then conditional compilation? My current code looks like: public abstract class KnownFolders

Why/when is __declspec( dllimport ) not needed?

故事扮演 提交于 2019-12-27 12:17:15
问题 In a project using a server.dll and a client.exe, I have dllexport ed a server symbol from the server dll, and not dllimport ed it into the client exe. Still, the application links, and starts, without any problem. Is dllimport not needed, then??? Details: I have this 'server' dll: // server.h #ifdef SERVER_EXPORTS #define SERVER_API __declspec(dllexport) #else #define SERVER_API // =====> not using dllimport! #endif class SERVER_API CServer { static long s; public: CServer(); }; // server

How to wrap C++ DLL in C# with pointers as parameters?

﹥>﹥吖頭↗ 提交于 2019-12-25 17:05:16
问题 I am trying to call some functions from a C++ DLL file in my C# program. But I got stuck when it comes to pointers. Could somebody point me to the right direction? Here's the C++ header file with the target functions: #pragma once #ifdef STCL_DEVICES_DLL #define STCL_DEVICES_EXPORT extern "C" _declspec(dllexport) #else #define STCL_DEVICES_EXPORT extern "C" _declspec(dllimport) #endif enum SD_ERR { SD_ERR_OK = 0, SD_ERR_FAIL, SD_ERR_DLL_NOT_OPEN, SD_ERR_INVALID_DEVICE, //device with such

Sharing variables between multiple Dlls in C++

主宰稳场 提交于 2019-12-25 07:54:23
问题 I need to share a variables (1000s) between 2 C++ Dlls. How should I do that? MyVariables.Dll contains: int a = 0; ModifyMyVariables.Dll contains: extern int a; a++; // do more stuff with a; What am i supposed to write in the following files? myvariables.h myvariables.cpp ModifyMyVariables.h ModifyMyVariables.cpp 回答1: You can share data between images (EXE, DLL...) using several fundamental mechanisms (using extern does not work to share data - it only instructs the linker and not the loader!

How to implement a class counter in DLL?

旧巷老猫 提交于 2019-12-25 03:24:40
问题 So far I have: // TypeCounter.h template <typename Base> class Counter : public Base { protected: static int typeIndexCounter; }; template <typename T, typename Base> class Bridge : public Counter<Base> { public: virtual ~Bridge() {} virtual int GetTypeIndex() const { return TypeIndex(); } static int TypeIndex() { static int typeIndex = typeIndexCounter++; return typeIndex; } }; // static variable definition template <typename Base> int Counter<Base>::typeIndexCounter; Use case is like: class

Passing an array of strings from C# to C++ DLL function and fill it in the DLL and get back

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-25 03:16:20
问题 I am writing a C# application that passes an empty string array of size 30 to a C++ DLL. This string array needs to be filled in the DLL and given back to the C# application. I my code I observe memory corruption at the end of function call from DLL. My C++ DLL code is as follows: SAMPLEDLL_API BOOL InitExecution (wchar_t **paszStrings, int count) { for (int i = 0 ; i < count; i++) { mbstowcs(*(paszStrings + i), "Good",4); //*(paszStrings + i) = "Good"; } return TRUE; } My C# code is string[]

Problems with dllimport in c# under Windows 7 x32

拈花ヽ惹草 提交于 2019-12-25 02:19:53
问题 Iam having problems with dll import in c#. I created library under windows xp x32 and tried to use it on windows 7 x32. My library is using another libraries called opnecvsharp which uses dllimport to opencv libraries for c++. Iam sure i added opencv.dlls to the same folder as executable file. I tried to run exe as admin, disable UAC, add path to dll in PATH variable, but none of those helped me. How I can make my program see dlls ? The error in picture shows that program doesnt see opencv

Where should I put C# dll in Metro Style Appc#

人盡茶涼 提交于 2019-12-25 01:07:40
问题 I am trying to import dll from Metro Style App. But I don't know where should I put dll. Please reply to me. 回答1: You can only reference DLLs built against WinRT. Typically these can be added via nuget, or alternatively added as a project, and using a project reference. Using other approaches is likely to fail certification, and not allow you to distribute your app to the general public. 来源: https://stackoverflow.com/questions/12685805/where-should-i-put-c-sharp-dll-in-metro-style-appc

Using 32 bit Delphi dll in ASP.NET?

徘徊边缘 提交于 2019-12-25 01:06:49
问题 First, it working fine in Visual Studio 2010 when I do the testing. But I tried 4 of the following to publish into IIS7 on 64bit windows 7, but is still not working: 1.Visual Studio 2010 Publish -> Build -> General -> Platform Target: Any CPU 1-A: IIS7: ASP.Net v4.0, Enable 32-Bit Application = False Error: Server Error in '/TestDll' Application. -------------------------------------------------------------------------------- An attempt was made to load a program with an incorrect format.

DllImport incomplete names

不羁的心 提交于 2019-12-24 18:05:07
问题 I am using several P/Invokes under .NET. However, I want my library to work both in Windows and Linux, preferably with the same binaries. Since the native library I depend on is available on multiple platforms, I was hoping to just have them along with my managed library's binaries. Right now I'm using something like this: [DllImport("/usr/lib/libMYLIBNAME.so.1")] But this obviously only works for Linux. I was considering that I could possibly copy that binary from /usr/lib and distribute