Click here to Skip to main content
15,910,471 members
Home / Discussions / C#
   

C#

 
GeneralSockets and ArrayLists Pin
obelisk2915-Jun-05 8:33
obelisk2915-Jun-05 8:33 
GeneralRe: Sockets and ArrayLists Pin
eggie515-Jun-05 19:21
eggie515-Jun-05 19:21 
GeneralImaging Application - not enough RAM Pin
Libor Tinka15-Jun-05 8:03
Libor Tinka15-Jun-05 8:03 
GeneralRe: Imaging Application - not enough RAM Pin
DavidNohejl15-Jun-05 8:19
DavidNohejl15-Jun-05 8:19 
GeneralRe: Imaging Application - not enough RAM Pin
Judah Gabriel Himango15-Jun-05 8:30
sponsorJudah Gabriel Himango15-Jun-05 8:30 
GeneralRe: Imaging Application - not enough RAM Pin
Dave Kreskowiak15-Jun-05 8:51
mveDave Kreskowiak15-Jun-05 8:51 
GeneralRe: Imaging Application - not enough RAM Pin
DavidNohejl15-Jun-05 12:44
DavidNohejl15-Jun-05 12:44 
GeneralRe: Imaging Application - not enough RAM Pin
JDUK15-Jun-05 12:12
JDUK15-Jun-05 12:12 
GeneralRe: Imaging Application - not enough RAM Pin
Dave Kreskowiak15-Jun-05 18:52
mveDave Kreskowiak15-Jun-05 18:52 
GeneralRe: Imaging Application - not enough RAM Pin
Christian Graus15-Jun-05 13:48
protectorChristian Graus15-Jun-05 13:48 
GeneralRe: Imaging Application - not enough RAM Pin
Libor Tinka16-Jun-05 1:02
Libor Tinka16-Jun-05 1:02 
GeneralDetecting New Mail -- Exchange Server 2000 Pin
JMKerp295815-Jun-05 7:47
JMKerp295815-Jun-05 7:47 
GeneralNumber of pages in PrintPreviewControl Pin
Luis Alonso Ramos15-Jun-05 7:47
Luis Alonso Ramos15-Jun-05 7:47 
GeneralRe: Number of pages in PrintPreviewControl -- solved Pin
Luis Alonso Ramos15-Jun-05 8:50
Luis Alonso Ramos15-Jun-05 8:50 
GeneralOffice Interop - Populating Checkboxes Pin
tsmyrnio15-Jun-05 7:43
tsmyrnio15-Jun-05 7:43 
QuestionGDI+ drawing strings causes messed gaps between letters - how to fix? Pin
iliyang15-Jun-05 7:16
iliyang15-Jun-05 7:16 
AnswerRe: GDI+ drawing strings causes messed gaps between letters - how to fix? Pin
MoustafaS15-Jun-05 8:25
MoustafaS15-Jun-05 8:25 
GeneralRe: GDI+ drawing strings causes messed gaps between letters - how to fix? Pin
iliyang15-Jun-05 11:16
iliyang15-Jun-05 11:16 
GeneralPassing strings from C++ to C# Pin
Paul Largent15-Jun-05 6:51
Paul Largent15-Jun-05 6:51 
I have successfully written a C++ DLL and can pass integer types from C++ to C# using the DllImport method. However I can not figure out how to pass a string (byte array or any other type) from my C++ dll to C#.

The C++ DLL side compiles without error and creates a DLL file. The C# side produces compiler errors no matter how I try to pass the string (have tried everything I can think of). Since Interoperation is a

"virtue" in Visual Studio I am sure that there is a simple solution but it eludes me. Here are the relevant code sections:

In C++ DLL header (.h)
extern "C" __declspec(dllexport) int addfive(int x);
extern "C" __declspec(dllexport) char* putFolderList();

In C++ DLL source (.cpp)
int addfive(int i) { return i+5 ;}
char* putFolderList(){ return "my string" ;}

In C#:
using System.Runtime.InteropServices;
[DllImport("DLLBuildTest.dll")]
static extern int addfive(int x); // VALID Smile | :)
static extern char* putFolderList(); // NOT Valid Frown | :(

errors (2) and warnings (1) from C# compilation:
#1 - warning CS0626: Method, operator, or accessor 'DLLCaller.Form1.putFolderList()' is marked external and has no attributes on it. Consider adding a DllImport attribute to specify the external implementation
@2 - error CS0214: Pointers may only be used in an unsafe context
#3 - error CS0029: Cannot implicitly convert type 'char*' to 'string'

My question is: What is a valid method for passing a string from a C++ DLL to a C# program?



Paul Largent
GeneralRe: Passing strings from C++ to C# Pin
S. Senthil Kumar15-Jun-05 6:56
S. Senthil Kumar15-Jun-05 6:56 
GeneralObtaining a reference to the TreeView item in a context menu Pin
SerialHobbyist15-Jun-05 6:28
SerialHobbyist15-Jun-05 6:28 
GeneralRe: Obtaining a reference to the TreeView item in a context menu Pin
S. Senthil Kumar15-Jun-05 7:00
S. Senthil Kumar15-Jun-05 7:00 
GeneralRe: Obtaining a reference to the TreeView item in a context menu Pin
SerialHobbyist16-Jun-05 2:48
SerialHobbyist16-Jun-05 2:48 
GeneralHashTable Pin
horacyjr15-Jun-05 6:05
horacyjr15-Jun-05 6:05 
GeneralRe: HashTable Pin
DavidNohejl15-Jun-05 6:28
DavidNohejl15-Jun-05 6:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.