The C# way of doing this is by letting the marshaler handle the char*
stuff while you work with a string:
[DllImport("pjsipDlld")]
static extern int dll_registerAccount(
[MarshalAs(UnmanagedType.LPStr)]string username,
[MarshalAs(UnmanagedType.LPStr)]string password);
Replace LPStr
with LPWStr
if you’re working with wide chars.
Related Contents:
- How to get parent process in .NET in managed way
- Why are Cdecl calls often mismatched in the “standard” P/Invoke Convention?
- How to deal with files with a name longer than 259 characters?
- Reading a C/C++ data structure in C# from a byte array
- Unable to load DLL (Module could not be found HRESULT: 0x8007007E)
- Win32 API function to programmatically enable/disable device
- using a class defined in a c++ dll in c# code
- Passing strings from C# to C++ DLL and back — minimal example
- PInvoke for C function that returns char *
- Working example of CreateJobObject/SetInformationJobObject pinvoke in .net?
- Bring a window to the front in WPF
- Global hotkey in console application
- Best way to access COM objects from C#
- Move window when external application’s window moves
- Unblock File from within .net 4 c#
- Marshal C++ struct array into C#
- How do I handle null or optional DLL struct parameters
- How do I call C++/CLI from C#?
- pinvokestackimbalance — how can I fix this or turn it off?
- No console output when using AllocConsole and target architecture x86
- How do I pinvoke to GetWindowLongPtr and SetWindowLongPtr on 32-bit platforms?
- A call to PInvoke function ‘[…]’ has unbalanced the stack
- How to return text from Native (C++) code
- Using a 32bit or 64bit dll in C# DllImport
- How do I marshal a struct that contains a variable-sized array to C#?
- Passing a vector/array from unmanaged C++ to C#
- When to use ReleaseComObject vs FinalReleaseComObject? [duplicate]
- Moving mouse cursor programmatically
- Show Authentication dialog in C# for windows Vista/7
- Are P/Invoke [In, Out] attributes optional for marshaling arrays?
- Set DllImport attribute dynamically
- Add offset to IntPtr
- How can I pass a pointer to an array using p/invoke in C#?
- Lock Windows workstation programmatically in C#
- PInvoke C#: Function takes pointer to function as argument
- Target 32 Bit or 64 Bit native DLL depending on environment
- Change keyboard layout from C# code with .NET 4.5.2
- WinApi – GetLastError vs. Marshal.GetLastWin32Error
- C# – How To Convert Object To IntPtr And Back?
- C# Deserializing a struct after receiving it through TCP
- How to download image from URL
- How to create a XSD schema from a class?
- How do I use the C#6 “Using static” feature?
- C# vs C – Big performance difference
- Convert words (string) to Int
- Visual Studio 2013 doesn’t discover unit tests
- EF Data Context – Async/Await & Multithreading
- Why GetType returns System.Int32 instead of Nullable? [duplicate]
- How to get awaitable Thread.Sleep?
- Parallel.For(): Update variable outside of loop