LPSTR an Funktion übergeben

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

From: Thorsten Hübbel (th.huebbel_at_web.de)
Date: 06/09/04


Date: Wed, 9 Jun 2004 02:33:02 -0700

Hallo NG,

habe folgendes Problem:
hab in mein C# Programm eine dll eingebunden der ich einen
LPSTR wert übergeben muß in den auch der Rückgabewert
reingeschrieben wird.
Der Quellcode sieht so aus:

[DllImport("TEST.dll")]
public static extern void Encode([MarshalAs
(UnmanagedType.LPStr)] String szText);

[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
public struct Stringchange
{
[MarshalAs(UnmanagedType.LPStr)] public String szText;
}

private void button2_Click(object sender, System.EventArgs
e)
{
Stringchar test = new Stringchar();
test.szText = textBox1.Text;
Encode(test.szText);
textBox2.Text = test.szText;
}

Ich kann zwar das Programm ausführen jedoch wird in szText
kein neuer Wert reingeschrieben.
Also gehe ich davon aus das ich irgendwas mit dem LPSTR
falsch mache.

Hier ist noch der Auszug aus der DLL bschreibung:
durch.
Der Übergabewert ist vom Datentyp LPSTR (long pointer to a
nullterminated ANSI character array - VC++ string), der
Rückgabewert ebenso, die
Funktion hat keinen Returnwert ("void").

Hoffe Ihr könnt mir helfen.

Gruß

Thorsten Hübbel



Relevant Pages

  • Re: Optimization of code
    ... When I compile the code you gave me to search for string I get 3 errors, ... LPSTR found = strstr; ... I beg to differ that you didn't use CStringA ...
    (microsoft.public.vc.mfc)
  • RE: Question about different string type in VC++
    ... Since you have probably modified the string, ... I want to write a simple Trim() function to trim the spaces around a ... > LPSTR string. ... > CString sInput; ...
    (microsoft.public.vc.mfc)
  • Re: Need help calling a proprietary C DLL from Python
    ... LPBSTR = POINTER ... VmxInfo.argtypes = [LPHANDLE, LPSTR] ... res = VmxInfo, byref) ... Note how the string buffer parameter has NO odd games on it. ...
    (comp.lang.python)
  • Re: But..... WHY??? Access Violation
    ... Since the function later on pokes nulls into the string it's ... LPCSTR and LPSTR are stupid names for types anyhow. ...
    (comp.lang.cpp)
  • variable arguments question
    ... I've two questiond regarding variable arguments. ... I see that va_arg macro can be used, but if don't know type of ... void myPrintf(char *szText, ...) ... this string should show a ...
    (comp.lang.c)