dllimport

C# DllImport return type is TCHAR?

Hi, I have a c++ function with the following signature TCHAR *DXGetErrorDescription9(HRESULT hr); I have [DllImport("dxerr9.dll",EntryPoint="GetDXErrorString9")] static public extern string GetDXErrorString9(int DXError); how do i marshall string to TCHAR*? Thanks ...

How do I use an unmanaged class from a managed DLL in .net?

I have an unmanaged class that I'm trying to dllexport from a managed DLL. I'm trying to use the unmanaged class in another managed DLL. However, when I try to do this I get link errors. I've done this lots of times with unmanaged DLLs so I know how that works. I know how to use "public ref" etc in managed classes. Is there some flag s...

Calling C++ dll function from C#: Of structs, strings and wchar_t arrays.

Here's a simple problem I need to solve, but it makes me feel my hair turning gray as all my attempts are returning me the same error: "Attempted to read or write protected memory. This is often an indication that other memory is corrupt." I have a sample app written in C++ which makes a call to the dll. Here is the relevant code: ...

DllImport and ASP.NET

Hi, I'm having some problems with DllImport and ASP.NET because when I use a imported method ASP.NET loads the Dll and locks the file even after it finished using it. Is there any way to force ASP.NET to release the lock on the file? ...

C# formatting external Dll function parameters

I have yet to find a good reference on this topic. For this example we will take some C++ code that I'm trying to port over to C#. In C++ land we have the following prototype for an external library function: extern "C" DWORD EXPORT FILES_GetMemoryMapping( PSTR pPathFile, PWORD Size, PSTR MapName, PWORD PacketSize, PMAPPING ...

How to determine if the Caps Lock is toggled in a Silverlight Application?

In a Silverlight application's log in screen, i need to determine if Caps Lock is toggled. This is easy enough by handling the KeyUp or KeyDown event, however how does one determine if it is toggled on or off even if a key hasn't been pressed? The reason I want todo this is what if the user doesn't press Caps Lock while the Silverlight ...

How to get a stack for exception.

Hi guys I have a Winform application (C#) which imports some functions from dll. Sometimes when running the application i get the following exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. I catch it in AppDomain.CurrentDomain.UnhandledE...

DllImport - PreserverSig and SetLastError attributes

Hi On the MSDN I've found the following description for the two attributes: PreserveSig Set the PreserveSig field to true to directly translate unmanaged signatures with HRESULT or retval values; set it to false to automatically convert HRESULT or retval values to exceptions. By default, the PreserveSig field is true. SetLastError En...

Calling a simple VC DLL from VB6

Hi: I have a simple DLL written with VC6 with one function: __declspec(dllexport) int myfunc(long a, unsigned char *b, unsigned char *c, unsigned char *d, unsigned char *e) And im calling it from vb6 using: Declare Function myfunc Lib "mylib.dll" (ByVal a As Long, ByVal b As String, ByVal c As String, ByVal d As String, ByVal e As St...

Custom Types in/with DLLImport'ed / P/Invoke'd win32 dll?

Good afternoon, i am currently wrestling with an old .dll which functionality I have to re-use in a .Net application & I came so far to import the basic/easy functions/methods that return bool etc, but some do in fact also expect (or return) an type that is declared within the .dll. How would I handle this? How would I map/create that ...

Passing pointers from unmanaged code

Hi, I have a C# project that imports a C dll, the dll has this function: int primary_read_serial(int handle, int *return_code, int *serial, int length); I want to get access to the serial parameter. I've actually got it to return one character of the serial parameter, but I'm not really sure what I'm doing and would like to understan...

How to get Email title using MAPI on Windows Mobile?

I want to get email title in PockerOutlook in Windows Mobile, but currently Microsoft.WindowsMobile.PocketOutlook has the ability to: Enumerate messaging accounts. Send Email Send SMS Intercept SMS So I want to DLLImport MAPI.DLL to get its functions in order to get the title of email. I find this reference written in C++. It seems ...

Managed C++ - Importing different DLLs based on configuration file

I am currently writing an application that will serve a similar purpose for multiple clients, but requires adaptations to how it will handle the data it is feed. In essence it will serve the same purpose, but hand out data totally differently. So I decided to prodeed like this: -Make common engine library that will hold the common funct...

Enumerating DLL functions?

Hello guys, Is it possible to enumerate every function present in a DLL ? How about getting its signature ? Can I do this in C# ? Or do I have to go low level to do this? Regards and tks, Jose ...

Where can I find a reference explaining how to take a C/C++ function header and define it with dllimport in C#?

I am using setupapi.dll to determine USB device connectivity. It isn't working properly in 64 bit versions of windows (XP, Vista). I suspect that the declarations are not quite correct, but am not sure how to verify. MS doesn't seem to provide the dllimport information, but they do list all the function definitions. Is there a resour...

problem with NetServerEnum() in c#

I am developing an application which requires to list all the current LAN machines. Inorder to list all the workstations on a LAN, i have used NetServerEnum() after importing it. On running the program, it seemed to work fine. The two existing machines were detected correctly. However, i want the list to be refreshed whenever required ...

DllImport vs Declare in VB.NET

I notice in the MSDN documentation that there are multiple ways to declare a reference to a function in an external DLL from within a VB.NET program. The confusing thing is that MSDN claims that you can only use the DllImportAttribute class with Shared Function prototypes "in rare cases", but I couldn't find the explanation for this s...

Marshalling a Linked List

Apologies for duplicate posting. Hi I am having trouble marshalling a linked list from a DLL. ------C++ Structure and Function-------- struct localeInfo { WCHAR countryName[BUFFER_SIZE]; WCHAR localeName[BUFFER_SIZE]; localeInfo *next; } int GetSystemLocales(localeInfo **ppList); -----------C# Declarations----------- ...

The specified module could not be found - 64 bit dll

Hi Everyone, I had the 32 bit dll which is written using Native C, when I tried compiling with VC++(VS2008) for converting the dll to x64 by changing the platform it compiled. But when I tried to access the dll from my C# application which is also 'x64' platform it fails to load the dll. I used Dllimport for linking the dll with my appl...

dllimport unable to load the dll

Hi Everyone, I found Stack Overflow is one among the best group for all our clarifications. I have the native dll written in C. I compiled the proj using VC++ (VS 2008), Using my C# application I called the dll functions through Dllimport. The problem is it fails to load the dll. It says unable to load the dll. I have compiled to the p...