|
I just tried with, with the space between string and the brackets; it didn't work.
|
|
|
|
|
Eric Houser wrote:
public string[] strGeoq = new string[30];
strAnimalsq[1] = "Blah Blah Blah";
Is this your sig or the error code?
leppie::AllocCPArticle("Zee blog"); Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.
|
|
|
|
|
Eric Houser wrote:
public string[] strGeoq = new string[30];
strAnimalsq[1] = "Blah Blah Blah";
Assuming this is your code as it is now
class Test
{
public Test()
{
}
public string[] strGeoq = new string[30];
strGeoq[1] = "Blah Blah Blah";
}
It can't be done that way, it would have to be something like this
class Test
{
public Test()
{
}
public string[] strGeoq = new string[30];
public void Init()
{
strGeoq[1] = "Blah Blah Blah";
}
}
or
class Test
{
public Test()
{
}
public string[] strGeoq = {"Blah, Blah, Blah", "Another Blah", etc"};
}
Michael
But you know when the truth is told,
That you can get what you want or you can just get old,
Your're going to kick off before you even get halfway through.
When will you realise... Vienna waits for you? - "The Stranger," Billy Joel
|
|
|
|
|
ok i have this case and try almost everething and dont work ..
C++ Dll:
typedef BYTE *CCSTR;
CCSTR __stdcall Example(CCSTR data)
{
//do somthing
}
C#:
[DllImport("test.dll",CharSet=CharSet.Auto,
CallingConvention=CallingConvention.StdCall)]
static public extern string Example([MarshalAs(UnmanagedType.LPStr)] string Data) ;
if someone have idea what can be wrong that will be very cool
10x in advance
PS: Sry about my bad english
|
|
|
|
|
|
no error just dont retutn anything
|
|
|
|
|
You have CharSet set to CharSet.Auto , but your typedef clearly shows that only an ANSI string (single byte) would be supported. Set CharSet to CharSet.Ansi .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
i try it result is the same
|
|
|
|
|
Why don't you post some code. This can work and I've done it successfully in the past. You either pin the addresses yourself or use one of the methods from the System.Runtime.InteropServices.Marshal class, though you're limited in what you can do with them. All ths has to be done from within a safe context, unless you use the methods from the Marshal class and use IntPtr for the pointer fields in your struct.
EDIT: Wrong reply - mistook for a different P/Invoke thread today.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
<br />
typedef BYTE *BBSTR;<br />
BBSTR AllocString(UINT len)<br />
{<br />
return (BBSTR) SysAllocStringByteLen(NULL, len);<br />
}<br />
void ReAllocString(BBSTR *pbbstr, UINT len)<br />
{<br />
BBSTR tstr;<br />
tstr = AllocString(len);<br />
if(len > StringLen(*pbbstr))<br />
len = StringLen(*pbbstr);<br />
if(len > 0)<br />
memcpy(tstr, *pbbstr, len);<br />
FreeString(*pbbstr);<br />
*pbbstr = tstr;<br />
}<br />
BBSTR __stdcall decode(BBSTR data)<br />
{<br />
UINT i, j;<br />
BBSTR outstr;<br />
<br />
outstr = AllocString(StringLen(data) - 1);<br />
i = 0;<br />
j = 0;<br />
<br />
while(i + 1 < StringLen(data)) {
if(data[i] == 0x07) {<br />
i++;<br />
outstr[j] = data[i] ^ 0x0F;<br />
} else {<br />
outstr[j] = data[i];<br />
}<br />
<br />
i++;<br />
j++;<br />
}<br />
<br />
ReAllocString(&outstr, j);<br />
return outstr;<br />
}<br />
in VB this is defined like
Public Declare Function decode Lib "endecode.dll" (ByVal Data As String) As String
in C#
[DllImport("endecode.dll",CharSet=CharSet.ASCII,<br />
CallingConvention=CallingConvention.StdCall)]<br />
static public extern string decode ([MarshalAs(UnmanagedType.LPStr)] string Data) ;
but dont work
|
|
|
|
|
Next time, please use the <pre> tags around your code.
If it won't compile, that's because ASCII is not an enumeration member of the CharSet enum. The compiler error would tell you this.
Also, the endecode.dll library must be in your PATH environment variable somewhere (like %WINDIR%\ and %WINDIR%\System32, etc.), or in the application directory (from where the application is run, or whatever is set to the working directory). P/Invoking code from an unmanaged DLL requires that the DLL can still be found. In this case, usually, you'll get a FileNotFoundException or some other runtime exception.
Since your VB code works, there's really no reason to post your C/C++ code.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
dll is in the same directory but C# code dont work in this way
|
|
|
|
|
Um, yes it does. The CLR looks for native libraries in the same way that all other applications (unless hard-coded with a path) do. The CLR looks for managed assemblies in a different way, but the application path is still checked for assemblies. Trust me. I've been doing this since 1.0 beta days and, unlike most people these days, I do actually read everything I can about what I do.
You still have never mentioned what is happening all this time. Is an exception being thrown? Is it even compiling? Are you just not getting a return value back?
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
No exeptions
Just not getting a return value back
|
|
|
|
|
I just noticed, the strings are BSTR s. In this case, they are unicode and must be handled as such. The following should work:
[DllImport("endecode.dll", CharSet=CharSet.Unicode /* Optional in this case */,
CallingConvention=CallingConvention.StdCall)]
[return: MarshalAs(UnmanagedType.BStr)]
static extern string decode([MarshalAs(UnmanagedType.BStr)]string data); BSTR is #defined as wchar_t , which is a wide character. This will never by ANSI on any platform. Before you posted something that implied the string was ANSI.
Also, make sure your C function declaration uses the C style declaration, otherwise it will be decorated. Since VB can all it, it's probably already correct. You can make sure by using the Dependency Walker (depends.exe), which is part of the Platform SDK and - if you choose the default options when installing VS.NET - should be in the <VS.NET Install Dir>\Vc7\PlatformSDK\bin directory. Open your unmanaged library and you should see the exported function. There should be no decoration (i.e., ordinals, etc.) on the function. If there is, you can forward-declare it like so:
#ifdef __cplusplus
extern "C" {
#endif
BSTR __stdcall decode(BSTR data);
#ifdef __cplusplus
}
#endif You can use a .DEP file, too, but that's "out-dated".
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
How do I change the location of a control in C# within the code; could someone tell me what I'm doing wrong? Here's what I have:
pboP1.Location.X = 16;
pboP1.Location.Y = 96;
|
|
|
|
|
Location is a value type so your code won't work because the location you are changing isn't the location used by pboP1. (Actually, I have a feeling that the X and Y properties don't have setters either so this code should probably generate a compiler error)
What you need to do is:
pboP1.Location = new Point(16, 96)
EuroCPian Spring 2004 Get Together[^]
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
"Get in touch with your Inner Capitalist - I wish you much success!" -- Christopher Duncan, Lounge 9-Feb-2004
|
|
|
|
|
You can use Left and Top properties of
the control class to move the controls.
Thank You
Bo Hunter
|
|
|
|
|
Has anyone solved the (as far as I can tell) problem where moving the scroll bar with the mouse does not fire the VScroll event in a RichTextBox?
Appreciate any feedback...
|
|
|
|
|
Hey
I have a winservice as a .NET remote server. Now I also wants webservices, but I'm not sure to place the remote server under IIS. Is it possible to "talk" between a webservice application and a windows service on the same machine?
|
|
|
|
|
Anonymous wrote:
Is it possible to "talk" between a webservice application and a windows service on the same machine?
Yes, but webservice should be placed on the IIS of that machine.
Mazy
You're face to face,
With the man who sold the world - David Bowie
|
|
|
|
|
|
How what? You don't know how to call a webservice method from windows service? What exactly you want to do?
Mazy
You're face to face,
With the man who sold the world - David Bowie
|
|
|
|
|
Just the other way around ;o) I want to call my win service( .NET remote server) from a webservice. is it possible?
|
|
|
|
|
I need a hint about how to recieve packets (any type IP ,Tcp ,UDP) using C#
thanx alot
|
|
|
|