dllimport

Exporting global variables from DLL

江枫思渺然 提交于 2019-12-03 09:52:24
I'm trying to export a global variable from a DLL. Foo.h class Foo { public: Foo() {} }; #ifdef PROJECT_EXPORTS #define API __declspec(dllexport) #else #define API __declspec(dllimport) #endif API const Foo foo; Foo.cpp #include "Foo.h" const Foo foo; When I compile the above code, Visual Studio complains: foo.cpp(3) : error C2370: 'foo' : redefinition; different storage class 1> foo.h(14) : see declaration of 'foo' If I use: external const Foo foo; in Foo.h the compiler is happy but then the DLL does not export the symbol. I've managed to export functions with problems, but variables don't

Converting a Windows Dll to .lib for C++ Visual Studio 2008

可紊 提交于 2019-12-03 09:19:37
问题 I know there is a tool called Dll to lib but the developer is asking $1000. I only need to convert one library, once, so its not easy to justify that price. I tried IMPLIB32.EXE, but I just get empty .lib files. How can I accomplish this? Perhaps I can write a simple conversion app? Added1: The Dll's are typically stdcall not cdecl and written in older C like languages NOT C# or .NET or C++. I now need to call them from C++ apps. An example would be the SQLite.dll or zlib.dll. I do not have

Trying to create a Math Input Panel in C#

女生的网名这么多〃 提交于 2019-12-03 09:14:06
How do I create a Math Input Panel in C#? I have tried to put it into a dll and call it but it just closes right away. #include <stdafx.h> #include <atlbase.h> #include "micaut.h" #include "micaut_i.c" extern "C" __declspec(dllexport) int run() { CComPtr<IMathInputControl> g_spMIC; // Math Input Control HRESULT hr = CoInitialize(NULL); hr = g_spMIC.CoCreateInstance(CLSID_MathInputControl); hr = g_spMIC->EnableExtendedButtons(VARIANT_TRUE); hr = g_spMIC->Show(); return hr; } I call the dll function in C# and the panel pops up but disappears right away. Any suggestions? In your C# project, add a

C#: Access 32-bit/64-bit DLL depending on platform

时光怂恿深爱的人放手 提交于 2019-12-03 09:04:21
we use a self-written 32bit C++ DLL from our C# applications. Now we've noticed that when the C# applications are run on a 64bit system, the 64bit runtime is automatically used and of course the 32bit DLL can not be accessed from the 64bit runtime. My question is: is there a way of using the 32bit DLL? If not, if I created a 64bit version of the DLL, would it be easily possible to let the application choose which one to P/Invoke to? I'm thinking of creating two helper classes in C#: One that imports the functions from the 32bit DLL and one that imports from the 64bit DLL, then creating a

What is dllspec(dllimport) and dllspec(dllexport) means

折月煮酒 提交于 2019-12-03 04:02:08
After googling, i came to know that Dllimport makes the function available for other modules, is it mandatory to declare function with extern "c" identifier? Also, Dllexport means, Dll itself uses the function while compiling it says. so by default all functions present in DLL are dllexport? __declspec(dllexport) exports a symbol. It makes it available from outside a DLL. __declspec(dllimport) imports a symbol. It practically says "this symbol is not defined in this application, it needs to be imported from a DLL file". You don't have to declare it with extern "C" . If you don't use extern "C"

Add a UAC shield to a button and retain its background image?

别等时光非礼了梦想. 提交于 2019-12-03 03:11:36
Using C# and .Net 4.0 in a winforms application: Is it possible to add the UAC shield to a button and retain the buttons background image? How? This is what I'm using at the moment, but it removes the image... [DllImport("user32.dll")] public static extern int SendMessage(IntPtr hWnd, uint Msg, int wParam, int lParam); public static void UACToButton(Button button, bool add) { const Int32 BCM_SETSHIELD = 0x160C; if (add) { // The button must have the flat style button.FlatStyle = FlatStyle.System; if (button.Text == "") // and it must have text to display the shield button.Text = " ";

FindWindowEx from user32.dll is returning a handle of Zero and error code of 127 using dllimport

故事扮演 提交于 2019-12-03 02:41:09
I need to handle another windows application programatically, searching google I found a sample which handles windows calculator using DLLImport Attribute and importing the user32.dll functions into managed ones in C#. The application is running, I am getting the handle for the main window i.e. Calculator itself, but the afterwards code is not working. The FindWindowEx method is not returning the handles of the children of the Calculator like buttons and textbox. I have tried using the SetLastError=True on DLLImport and found that I am getting an error code of 127 which is "Procedure not found

Converting a Windows Dll to .lib for C++ Visual Studio 2008

此生再无相见时 提交于 2019-12-02 23:28:17
I know there is a tool called Dll to lib but the developer is asking $1000. I only need to convert one library, once, so its not easy to justify that price. I tried IMPLIB32.EXE, but I just get empty .lib files. How can I accomplish this? Perhaps I can write a simple conversion app? Added1: The Dll's are typically stdcall not cdecl and written in older C like languages NOT C# or .NET or C++. I now need to call them from C++ apps. An example would be the SQLite.dll or zlib.dll. I do not have access to the .lib files for these dll's. Added2: I re-wrote this code for VS2008 http://floodyberry

Unable to find type or namespace of imported DLL

左心房为你撑大大i 提交于 2019-12-02 18:13:50
问题 I downloaded the "smilenet-1.2.1-win64-academic" library from this page and imported the smileNET.dll in my Unity project. Then I restarted my visual studio, and when I tried to use the library, it gave me an error that the type or namespace could not be found. I tried using Smile; and using smileNET; as indicated in their documentation file Hello.cs but it did not work. I tried 64 bit version as well as 32 bit one. My unity version is 2018.1.8f1 64bit When I inspected the downloaded dll, it

Drawing my own title bar

…衆ロ難τιáo~ 提交于 2019-12-02 14:41:06
问题 I'm drawing part of the title bar in my WinForm applications. Is working Ok (placing the name of the company centered and in Orange) This is the code to do that at the form code: using System.Runtime.InteropServices; [DllImport("user32.dll")] private static extern IntPtr GetWindowDC(IntPtr hWnd); [DllImport("user32.dll")] private static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC); private Rectangle PosicionTexto() { string sTexto = String.Format("{0} : {1}", this.Text, "Trevo I.T."); sTexto