Click here to Skip to main content
15,886,857 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a string and i want to copy at specified memory location.
Suppose i have a pre-allocated memory represented by following unsafe code:

char* logFile


I have a generated string which contains the name of log file.
I want to copy that string on location represented by char*.

Please help me on this.


Also i have to copy specified number of characters from a given location
to specified location.

The code in delphi looks something like:

StrLCopy(msg, PChar(gsRootErrorMsg), MAX_ERR_MESSAGE);


where msg is character pointer:msg: PChar
and gsRootErrorMsg is string.


Help would be really appreciated.
Thanks.
Posted
Updated 13-Jan-11 12:00pm
v3
Comments
Manfred Rudolf Bihy 13-Jan-11 15:46pm    
I'm sure you have a reason for trying to do something like that from managed code. Can you enlighten us what exactly you're trying to achieve? Thanks!
Member 4581741 14-Jan-11 8:40am    
No .. i can use unmanaged code too.
I just want to copy the content located at source memory location to destination memory location x no of characters.

1 solution

Use c++/cli or interop, easier and less error prone. See:
Consuming Unmanaged DLL Functions[^]

Here is a small example on exporting dll functions from Delphi:
http://delphi.about.com/od/windowsshellapi/a/dll_basics.htm[^]

example:
C#
using System.Runtime.InteropServices;

public class Win32 {
     [DllImport("user32.dll", CharSet=CharSet.Auto)]
     public static extern IntPtr MessageBox(int hWnd, String text,
                     String caption, uint type);
}

public class HelloWorld {
    public static void Main() {
       Win32.MessageBox(0, "Hello World", "Platform Invoke Sample", 0);
    }
}



Regards
Espen Harlinn
 
Share this answer
 
v3
Comments
Member 4581741 13-Jan-11 15:49pm    
I am using interopservice but i dnt knw the syntax to copy the string content to a specified location.

I think there should be something in C# directly which can do that.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900