Re: Unmanaged code(dll) function: int myfunc (char* temp)

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hi and sorry for the interference.

As Chris is saying, char* is 8bit ANSI character based. Try using TCHAR*
(16bit UNICODE). Perhaps your problem resides on native library.

regards,


--
José Miguel Torres
jtorres_diaz~~ARROBA~~terra.es
http://jmtorres.blogspot.com
http://www.desarrolloMobile.NET


"Murthy" <Murthy@xxxxxxxxxxxxxxxxxxxxxxxxx> escribió en el mensaje
news:1856CE89-2980-406C-A531-1827CDB428C2@xxxxxxxxxxxxxxxx
C++ code:

int myfunc(char* temp)
{
//Assigning an value to temp
strcpy(temp,L"abcd");

}
I am using char* not TCHAR*

Can you help me how to get the value of temp when using string builder
from managed code



"<ctacke/>" wrote:

Without seeing the code in your C method, there's no way to know what's
wrong.


--
Chris Tacke
OpenNETCF Consulting
Managed Code in the Embedded World
www.opennetcf.com
--


"Murthy" <Murthy@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:C70DC73E-98B2-481B-BABE-03FDCF1C40B3@xxxxxxxxxxxxxxxx
Hi,
Thanks for ur Reply....
I tried StringBuilder it worked, But there is some problem with
conversion
i
think.
When i tried to convert it to string as sb.Tostring(), it is giving me
some
junk characters which are not alphanumeric.

Can u tell me what i need to do to convert the stringbuilder sb to some
alphanumeric string.

Murthy.

"<ctacke/>" wrote:

First thing to know is that CE doesn't store strings in a char* type,
it
uses UTF16, so they are wchar_t.

If the native DLL will be putting data into that variable, you need to
allocate enough memory for it before the call. The easiest way is
with a
StringBuilder.

int myfunc (TCHAR* temp)
{
.....
}

[DllImport("mylib.dll")]
public static extern int myfunc(StringBuilder sb);

void MyCall()
{
StringBuilder sb = new StringBuilder(255);
int ret = myfunc(sb);
}


--
Chris Tacke
OpenNETCF Consulting
Managed Code in the Embedded World
www.opennetcf.com
--


"Murthy" <Murthy@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:5F9D1506-CD19-4390-B633-0BDE53BCC1DA@xxxxxxxxxxxxxxxx
Hi,
I want to do an unmanaged call to an DLL
Unmanaged code(dll) function: int myfunc (char* temp)
Here return int type determines the Success.
After execution of the function temp will contain an value

How to do the unmanaged call to this function from c# and later how
to
retrieve the value from temp, which hold a string value.

thanks in Advance,
Murthy









.



Relevant Pages

  • Re: Unmanaged code(dll) function: int myfunc (char* temp)
    ... //Assigning an value to temp ... I am using char* not TCHAR* ... Can you help me how to get the value of temp when using string builder ... int myfunc ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Unmanaged code(dll) function: int myfunc (char* temp)
    ... //Assigning an value to temp ... I am using char* not TCHAR* ... Can you help me how to get the value of temp when using string builder ... int myfunc ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Struggling with libraries
    ... void insert(char* insrt, char* source, int place){ ... I tried returning temp instead and that doesn't work either, ... quite the string that exists in the function (and the compiler warns about ...
    (comp.lang.c)
  • Re: MODIFIED: Copying a CString to a std::string via TCHAR
    ... It seems to me that you are not modifying the Name string in DoWidget function, so why don't you pass the string parameter using proper const-correctness? ... int Result = DoWidget; ... CString Ralf = ... ... CString::operator LPCTSTR (i.e. const TCHAR*) will be called. ...
    (microsoft.public.vc.mfc)
  • Re: shorten string length by 1
    ... The following code displays the string. ... loop and different strings are displayed without problems. ... temp= strlen; ... int main ...
    (comp.lang.c)