|
That is what I was thinking as well, but it's only 2 characters long and the string I'm looking to return is around ~100 characters long....I am almost certain that the dll I'm using works soley with unicode characters. And also, isn't a char in .NET 16-bit? So my cast from the IntPtr to a string using a cast as char* would show that the dll is using unicode characters...correct? The integer value of position 0 is 8496 and of position 1 is 1937 in the string contained in StringBuilder. The 8496 correspoond to ascii characters 33 (!) and 48 (0), which are not valid for what I'm looking to get back.
Edit: Some further testing. Ran it multiple times, and same values come out, the string I am looking for is different each time (it's a like creating a new guid).
Jason
|
|
|
|
|
I am right about ref and out , trust me. Interop is something I've studied more in-depth than anything with .NET, and I study everything pretty deeply.
Anyway, I didn't look over the whole thing initially since Dave was helping you.
Following the messages below this one, you're right that chars in .NET are natively 16-bits, but they can be marshalled as 8-bit chars as well depending on the MarshalAsAttribute , or the StructLayoutAttribute and the DllImportAttribute (using the CharSet property for each) if you don't specify the MarshalAsAttribute (not always a need to).
So you're not really changing what a char is in managed code, but you're changing how its marshalled to and from unmanaged code.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
After reviewing the whole thread, I think I found your problem.
First, a "string is just an array of chars, so char* or char[] (for which a reference references the first element and is typically null-terminated, except for VB which sucks).
So, a PPWSTR is actually a char** , which is not only unnecessary in most cases, but probably incorrect. Also, Dave is right below (man, it feels weird saying that because my CEO who tries to program is named "Dave" and he's always wrong) - BSTR s and LPWSTR s (PWSTR , too) are not the same but can be. Here it's better to assume they won't be and just use UnmanagedType.LPWStr .
So, if your native function is declared as:
void myfunc(PWSTR a, PWSTR b, PWSTR c); ...your P/Invoked declaration should look like:
[DllImport("whatever.dll", CharSet=CharSet.Unicode)]
private static extern void MyFunc(string a, string b, string c); If one of those is meant to be an [out] param, you can use the OutAttribute but do not use out or ref for a reference type except in rare circumstances where you would have something like PPWSTR .
As I explained above, strings are already reference types. Very rarely do you use ref or out with reference types (interfaces, strings, etc.). There are types, though. QueryInterface , for example, uses LPVOID* , which is void** , so that's one place you'd need it (although there's no reason since the Marshal class already encapsulates this - but it's just an example off the top of my head).
Hope this helps.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I completely understand what you are saying. Here is the problem, my function is declared as such:
void myfunc(PWSTR a, PWSTR b, PWSTR* c);
c will be a pointer to the PWSTR created by the function....
What is the best way to handle this?
|
|
|
|
|
If you can't change it (because you really doing need a PWSTR* to get the output), declare your method like so:
[DllImport("whatever.dll", CharSet=CharSet.Unicode)]
private static extern void myfunc(string a, string b, out string c);
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Please have my children.....i love you
Thanks so much for you help!
Just to clear something up, what's the difference between declaring ref and declaring out?
|
|
|
|
|
The difference between the two if that a ref parameter must be initialized to something before it is passed into the function being called. Out parameters don't need to be initialized.
Make sense? If not, think of an Array being passed into a function. Do you want/need to initialize the array, like defining it's dimensions and types, before you pass its pointer to the function or do you want the function to create the array for you?
RageInTheMachine9532
|
|
|
|
|
i have a question ...
could you translate this vb code to c# ? i tried it, but i failed ...
Private Sub Command1_Click()
Dim x As Integer
Dim var1 As Integer
Dim var2 As Integer
List1.Clear
x = Val(Text1.Text)
varX = Int(x / 3) + 1
var1 = 1
var2 = 1
var3 = 1
Do While Not var1 = x
tel = tel + 1
getal1 = var1
var2 = var2 + 1
getal2 = var2
getal3 = Val(x) - Val(getal1) - Val(getal2)
If getal1 <> getal2 And getal1 <> getal3 And getal2 <> getal3 And getal2 < getal3 Then
List1.AddItem getal1 & " + " & getal2 & " + " & getal3
Else
var1 = var1 + 1
var2 = var1
If tel = var3 + 1 Then Exit Do
var3 = tel
End If
Loop
End Sub
I'm making a program that when you enter a number, returns all the possibility's of how to make that number
example: ENTER : 14 Returned items = 1+2+11 = 14
1+3+10 = 14
1+4+9 = 14
1+5+8 = 14
1+6+7 = 14
2+3+9 = 14
2+4+8 = 14 ....
and you can't use the same number twice
... or the same combinations ex. 14 = 1 + 2 + 11 but not 2 + 1 + 11
i really hope somebody can help me !!!!
|
|
|
|
|
What have you produced in C#?
How have you failed?
Perl combines all the worst aspects of C and Lisp: a billion different sublanguages in one monolithic executable. It combines the power of C with the readability of PostScript. -- Jamie Zawinski
|
|
|
|
|
First off, let me say that you need to register the click event. So, before I convert this big block, let me know if you've done this. If you're using VS.NET and you double-click on the button in the designer, it should be taken care of for you. Let me know.
Michael Flanakin
Web Log
|
|
|
|
|
i registered the click event ...
and i'm using VS.Net ...
|
|
|
|
|
What's the error you got? There are a lot of unknowns in this method. It's hard to tell if something is supposed to be a local var or a class property. You would probably be better off posting the C# line that has the problem.
Michael Flanakin
Web Log
|
|
|
|
|
I may be wrong, but this smacks of someone asking for help on a homework assignment...
|
|
|
|
|
I'm glad I wasn't the only one to think that.
Michael Flanakin
Web Log
|
|
|
|
|
And there's nothing wrong in providing help to him. What's wrong is doing his homework...
That's why I asked him what he tried, so I can point him some minor error and let him follow his path...
Perl combines all the worst aspects of C and Lisp: a billion different sublanguages in one monolithic executable. It combines the power of C with the readability of PostScript. -- Jamie Zawinski
|
|
|
|
|
It is an examn assignment ...
but i'm really bad in these things , ...
so any help is good help
|
|
|
|
|
this is what i have in c# ...
but it doesn't work ... :s
I think i'd better work with an arraylist ... but don't know exactly how ...
private void Command1_Click()
{
int x = 0;
int var1 = 0;
int var2 = 0;
List1.Clear();
x = Microsoft.VisualBasic.Conversion.Val(Text1.Text);
varX = Microsoft.VisualBasic.Conversion.Int(x / 3) + 1;
var1 = 1;
var2 = 1;
var3 = 1;
while (! (var1 == x))
{
tel = tel + 1;
getal1 = var1;
var2 = var2 + 1;
getal2 = var2;
getal3 = Microsoft.VisualBasic.Conversion.Val(x) -
Microsoft.VisualBasic.Conversion.Val(getal1) -
Microsoft.VisualBasic.Conversion.Val(getal2);
if (getal1 != getal2 & getal1 != getal3 & getal2 != getal3 & getal2 < getal3)
{
List1.AddItem getal1 + " + " + getal2 + " + " + getal3;
}
else
{
var1 = var1 + 1;
var2 = var1;
if (tel == var3 + 1)
{
break;
}
var3 = tel;
}
}
}
}
}
|
|
|
|
|
if tried some more ... there are a lot of wrong things in it but, hey ... who's perfect ?
maybe if i keep on trying, i'll get there ...
private void Command1_Click()
{
ArrayList getal = new ArrayList();
int x = 0;
int var1 = 0;
int var2 = 0;
List1.ClearSelected();
x = Convert.ToInt32(Text1.Text);
varX = (x%3)+1;
var1 = 1;
var2 = 1;
var3 = 1;
while (! (var1 == x))
{
tel = tel + 1;
getal1 = var1;
var2 = var2 + 1;
getal2 = var2;
getal3 = getal3 = Val(x)- Val(getal1)- Val(getal2);
if (getal1 != getal2 & getal1 != getal3 & getal2 != getal3 & getal2 < getal3)
{
List1.Items.Add(getal[i].ToString());
}
else
{
var1 = var1 ++;
var2 = var1;
if (tel == var3 ++)
{
break;
}
var3 = tel;
}
}
}
}
}
|
|
|
|
|
Hi,
I am developing C# programs nowadays, I want to enter game programming with DirectX9 and C#. Can somebody give a good starting point (book, web source or some other source)?
Thank you all.
Cem Louis
|
|
|
|
|
|
I'll second the suggestion of Introduction to 3D Game Engine Design...full of information.
And, with some smart optimizations, you can whittle away that 20% slowdown...not to equal native, mind you, but it is "optimizable"
|
|
|
|
|
I have got a datagrid. The datasource of this datagrid is a datatable in a dataset ...
In the datagrid, i have got my combobox added in it and some boolean cells ....
The problem i met is that when i changed the value from a cell ... the dataset didn't updated immediately and kept on the obsolete data .... but when move my mouse focus to another cell and change the value .... the previous modification made to the datagrid has not updated to the dataset .......
What is the problem actually ? .. Any help will be appreciated .
|
|
|
|
|
I'm trying to write this class to filter urls from asp to aspx pages but it looks like .Net doesn't deal with .asp pages any more. Could you please suggest any alternative to this or how to make it work?
Thanks a lot.
Here is the code I'm using in the class:
using System;
using System.Web;
using System.Xml;
namespace URLChanger
{
///
/// Summary description for Class1.
///
public class ChangeURL : IHttpModule
{
///
/// Init is required from the IHttpModule interface
///
/// <param name="Appl" />
public void Init(System.Web.HttpApplication Appl)
{
//make sure to wire up to BeginRequest
Appl.BeginRequest+=new System.EventHandler(Rewrite_BeginRequest);
}
///
/// Dispose is required from the IHttpModule interface
///
public void Dispose()
{
//make sure you clean up after yourself
}
///
/// To handle the starting of the incoming request
///
/// <param name="sender" />
/// <param name="args" />
public void Rewrite_BeginRequest(object sender, System.EventArgs args)
{
//process rules here
//cast the sender to an HttpApplication object
System.Web.HttpApplication Appl=(System.Web.HttpApplication)sender;
string fullUrl = Appl.Request.Url.AbsoluteUri.ToLower();
string urlPath = Appl.Request.Path.ToLower();
string[] folders = urlPath.Split('/');
string filename = urlPath.Substring(urlPath.LastIndexOf('/')+1);
string file = filename.Substring(0, filename.IndexOf('.'));
string ext = filename.Substring(filename.LastIndexOf('.')+1);
string parms = Appl.Request.QueryString.ToString();
string dest;
if((Appl.Request["tag"]) == null)
{
if(folders.Length > 3)
{
string fld = folders[2].ToString();
//System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
//doc.Load("http://localhost/URLCHangerDemo/xmlfile1.xml");
//string srch = "/Dealers/PowerPage[@url='" + folders[2].ToString() + "']";
//System.Xml.XmlNode foundNode = doc.SelectSingleNode(srch);
dest = "http://devweb.trader.ca/" + folders[2] + "/" + folders[3] + "?" + parms;
Appl.Response.Redirect(dest);
}
}
}
}
}
|
|
|
|
|
You have to configure IIS to use the aspnet_isapi.dll ISAPI filter to handle the .asp extension as well. You can do this by opening the Internet Information Manager from your Administrative Tools directory, get the Properties for the site and go to the Home Directory tab. Click on Configuration... and see how the others are configured.
ASP.NET is an ISAPI filter so it can only handle files that are associated with that ISAPI filter. ASP.NET never did handle .asp files, so here you'll have to re-associate .asp files with the ASP.NET filter.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks for reply.
Actually I did that and now when I try to see any .asp page I get this error:
This type of page is not served.
Description: The type of page you have requested is not served because it has been explicitly forbidden. The extension '.asp' may be incorrect. Please review the URL below and make sure that it is spelled correctly.
Requested Url: /mysite/WebForm2.asp
Any idea how to fix it.
Thanks.
|
|
|
|