Click here to Skip to main content
15,902,189 members
Home / Discussions / C#
   

C#

 
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 
GeneralRe: HashTable Pin
S. Senthil Kumar15-Jun-05 7:04
S. Senthil Kumar15-Jun-05 7:04 
GeneralValues writed by the visual studio designer Pin
Trambert15-Jun-05 5:10
Trambert15-Jun-05 5:10 
GeneralPanel scroll on drag Pin
ninja260515-Jun-05 3:49
ninja260515-Jun-05 3:49 
GeneralRe: Panel scroll on drag Pin
Carl Mercier15-Jun-05 4:15
Carl Mercier15-Jun-05 4:15 
GeneralMove Print Job Pin
Member 133372815-Jun-05 3:39
Member 133372815-Jun-05 3:39 
GeneralRe: Move Print Job Pin
Dave Kreskowiak15-Jun-05 4:18
mveDave Kreskowiak15-Jun-05 4:18 
QuestionXtraReports? Pin
Carl Mercier15-Jun-05 3:12
Carl Mercier15-Jun-05 3:12 
Questionhow to change column color of datagrid Pin
dexom15-Jun-05 3:04
dexom15-Jun-05 3:04 
GeneralForm closing event Pin
Anonymous15-Jun-05 2:51
Anonymous15-Jun-05 2:51 
GeneralRe: Form closing event Pin
jjansen15-Jun-05 3:43
jjansen15-Jun-05 3:43 
GeneralRe: Form closing event Pin
Tom Larsen15-Jun-05 5:10
Tom Larsen15-Jun-05 5:10 

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.