|
Without the API that you're using it's difficult to give you an example, but here's one I used recently for retrieving MIDI input messages. The function looks like this:
[DllImport("winmm.dll")]
public static extern UInt32 midiInOpen(
out IntPtr lphMidiIn,
UInt32 uDeviceID,
MidiProc dwCallback,
UInt32 dwCallbackInstance,
UInt32 dwFlags); The delegate looks like this:
internal delegate void MidiProc(
IntPtr handle,
UInt32 wMsg,
UInt32 dwInstance,
UInt32 dwParam1,
UInt32 dwParam2); The managed Open method that wraps the midiInOpen function in my MIDIInput class is:
public void Open()
{
if (!IsOpen)
{
UInt32 result = Functions.midiInOpen(out handle, ID, midiProc, ID, Constants.CALLBACK_FUNCTION);
if (result == Constants.MMSYSERR_NOERROR)
{
IsOpen = true;
Manager.openInputs.Add((Input)this);
OnOpened(EventArgs.Empty);
}
else
throw new MIDIException(GetErrorText(result));
}
} This class has a field
internal MidiProc midiProc;
and in the constructor I assign the midiProc to the method.
midiProc = MessageHandler;
When the delegate (callback) is called, it now calls my MessageHandler method which raises the event(s).
protected override void MessageHandler(IntPtr handle, uint wMsg, uint dwInstance, uint dwParam1, uint dwParam2)
{
switch (wMsg)
{
case Constants.MIM_DATA:
OnDataReceived(new DataReceviedEventArgs(dwParam1, dwParam2));
break;
case Constants.MIM_ERROR:
OnDataReceived(new DataReceviedEventArgs(dwParam1, dwParam2, true));
break;
}
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Here's a simplified version of what I posted above. This is not real world, but could be if there were no return values or parameters involved! This will be easier to follow I hope!
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
delegate void MyDelegate();
public partial class Form1 : Form
{
public event EventHandler FunctionCalled;
MyDelegate myDelegate;
public Form1()
{
InitializeComponent();
myDelegate = FunctionCallback;
}
public void CallNativeFunction()
{
function(myDelegate);
}
void FunctionCallback()
{
OnFunctionCalled(EventArgs.Empty);
}
protected virtual void OnFunctionCalled(EventArgs e)
{
EventHandler eh = FunctionCalled;
if (eh != null)
eh(this, e);
}
[DllImport("your.dll")]
static extern void function(MyDelegate callback);
}
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
The only way to ever understand delegates and events (as well as most other slightly abstract concepts) is by reading appropriate documentation, say a chapter in a tutorial book.
You may want to study this on delegates[^] and this on events[^].
To get you started, and oversimplifying a lot: a delegate almost is like a good old C function pointer;
and an event is a list of delegates.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Thank you Luc, now I understand what I've read about Delegates.
|
|
|
|
|
1. I have all the data in a DataTable. I have created the CrystalReport document using VS2005 by using labels, boxes etc. Now do I have to use formula fields to set the values in the document.
2. When I have all the documents created how can I send them all to the CrystalReportViewer at once for viewing?
For example, if I wanted to show all the orders of a customer and I have created a custom CrystalReport document for the orders.
CodingYoshi
Artificial Intelligence is no match for Human Stupidity.
|
|
|
|
|
CodingYoshi wrote: 1. I have all the data in a DataTable. I have created the CrystalReport document using VS2005 by using labels, boxes etc. Now do I have to use formula fields to set the values in the document.
Your Crystal Report is, i would hate the be the one to tell you, not going to work. Crystal reports work based on either Strongly Typed Datasets or Parameters. Let me save you the head ache, you want to use a Strongly Typed Dataset. Parameters are good for ... well parameters to filter your dataset or for something trivial like headers or something like that.
What you are going to want to do is create a new Dataset in your project, then make that mimic your data schema. After you have created your "Strongly Typed" Dataset add a new Crystal Report to your project and set the Datasource to your newly created Dataset.
When creating your Crystal Report you want to use the "Data Fields" to actually display data to the user. Labels and Boxes are for static content, Your going to have to work the Google to get more info on how to create Crystal Reports.
CodingYoshi wrote: 2. When I have all the documents created how can I send them all to the CrystalReportViewer at once for viewing?
Well this is extremely simple;
- Create a new form with a CrystalReportViewer on it
- Create a new instance of your report and call Load() on it
- Set the ReportDocument property ont he CrystalReportViewer to your new report instance
If at first you don't succeed ... post it on The Code Project and Pray.
|
|
|
|
|
Guess I should have mentioned that you can connect directly to your database from Crystal Reports, but its a bad idea due to the fact the if you want to deploy the report to a different server you have to recompile your app (if the reports are embedded) or your report (if you are loading your reports externally).
Oh yeah, and if you want to load an external report all you have to do is call the overridden Load() on the ReportDocument object passing it the path to the report document to load.
If at first you don't succeed ... post it on The Code Project and Pray.
|
|
|
|
|
Thanks! I am grabbing the data from the database from many tables, processing the data and then saving it in DataTable object. What I need to do now is create a strongly typed DataSet (As you mentioned) and fill it with data from the datatable. Then it should work, hopefully.
CodingYoshi
Artificial Intelligence is no match for Human Stupidity.
|
|
|
|
|
Hi,
So I am moving into a .net C# environment from the java eclipse RCP world. One of the things I appreciated most about eclipse RCP was the ability to use compontents that were prebuilt such as layout management and preferences, needing only to modify them with contributions.
Does .net have anything similar going on? For example, in eclipse all layout/docking was handled automatically once you added your widgets to a layout. Layouts were persistent across sessions- as the programmer all you had to do was tell the component where to go, eclipse did the rest of the notifications and redrawing.
Before I did the java thing, I programmed in VS 2003 C++ for several years, and I recall that we had to purchase 3rd party packages to accomplish most of what eclipse rcp provided for free. Has .net 2.0 or 3.0 provided anything like this?
Also, since I am obviously new to the who .net thing, where can I learn about the advantages of .net and how I can leverage it for my applications?
Thanks!
|
|
|
|
|
Hello,
I have a server with Windows Authentication enabled and I was trying to throw a request in c# to access it. My code looks like this:
webRequest = WebRequest.Create(myURL);
webRequest.Credentials = CredentialCache.DefaultCredentials;
webResponse = webRequest.GetResponse();
However, this is throwing an error:
System.Net.WebException: The request was aborted: The request was canceled. ---> System.FormatException: Invalid length for a Base-64 char array.
at System.Convert.FromBase64String(String s)
at System.Net.NTAuthentication.GetOutgoingBlob(String incomingBlob)
at System.Net.NegotiateClient.DoAuthenticate(String challenge, WebRequest webRequest, ICredentials credentials, Boolean preAuthenticate)
at System.Net.NegotiateClient.Authenticate(String challenge, WebRequest webRequest, ICredentials credentials)
at System.Net.AuthenticationManager.Authenticate(String challenge, WebRequest request, ICredentials credentials)
at System.Net.AuthenticationState.AttemptAuthenticate(HttpWebRequest httpWebRequest, ICredentials authInfo)
at System.Net.HttpWebRequest.CheckResubmitForAuth()
at System.Net.HttpWebRequest.CheckResubmit(Exception& e)
at System.Net.HttpWebRequest.DoSubmitRequestProcessing(Exception& exception)
at System.Net.HttpWebRequest.ProcessResponse()
at System.Net.HttpWebRequest.SetResponse(CoreResponseData coreResponseData)
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.GetResponse()
I am specially intrigued by the " Invalid length for a Base-64 char array." message. Does anybody have any ideas on what may be causing this?
I have to add that my webserver is *not* IIS. These are the http headers that the server responds with:
HTTP/1.1 401 UNAUTHORIZED
Content-Length: 25
Content-Type: text/plain; charset=UTF-8
Server: GeognoSIS/7.1.135.0 (Alpha)
WWW-Authenticate: Negotiate
X-Cadcorp-GeognoSIS-Licence: {"Vendor Information":"Debug-only unlicensed version"}
0.01s
GET /GoogleMapsService/GM.serv?REQUEST=getCapabilities&alloverlays=true HTTP/1.1
Authorization: Negotiate TlRMTVNTUAABAAAAt7II4gMAAwAuAAAABgAGACgAAAAGAHEXAAAAD0RFVjMwOURFVg==
The thread '_threadstartex' (0x6cc) has exited with code 0 (0x0).
Host: dev309.dev.cadcorp.net:4326
HTTP/1.1 401 UNAUTHORIZED
Content-Length: 25
Content-Type: text/plain; charset=UTF-8
Server: GeognoSIS/7.1.135.0 (Alpha)
WWW-Authenticate: Negotiate TlRMTVNTUAACAAAABgAGADgAAAA1woniyuFg72yjZX2QNQMCAAAAAJYAlgA+AAAABgBxFwAAAA9EAEUAVgACAAYARABFAFYAAQAMAEQARQBWADMAMAA5AAQAHgBEAGUAdgAuAGMAYQBkAGMAbwByAHAALgBuAGUAdAADACwARABFAFYAMwAwADkALgBEAGUAdgAuAGMAYQBkAGMAbwByAHAALgBuAGUAdAAFABYAYwBhAGQAYwBvAHIAcAAuAG4AZQB0AAcACACud9kb5wbKAQAAAAA
X-Cadcorp-GeognoSIS-Licence: {"Vendor Information":"Debug-only unlicensed version"}
Also, I have to add that I am able to fire successfully the request in IE, so I was guessing there is some problem with the DefaultCredentials...
Any suggestions or comments would be really appreciated!
Thanks in advance,
Regards,
Jo
|
|
|
|
|
Just a thought, could be because your request is empty.
If at first you don't succeed ... post it on The Code Project and Pray.
|
|
|
|
|
Hi, Thanks for the reply.
I did a little bit of more research on this, and found out that the request, when fired from IE has a successfull http Ok response. These are the headers send by client and server during the negotiation:
GET /ogcservice/wmts.impl?service=wmts&request=getcapabilities&version=1.0.0 HTTP/1.1
Accept: image/gif, image/jpeg, image/pjpeg, application/x-ms-application, application/vnd.ms-xpsdocument, application/xaml+xml, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-silverlight, application/x-shockwave-flash, **
Accept-Language: en-gb
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618)
Accept-Encoding: gzip, deflate
Host: localhost:4326
Connection: Keep-Alive
Authorization: Negotiate TlRMTVNTUAABAAAAl7II4gMAAwAuAAAABgAGACgAAAAGAHEXAAAAD0RFVjMwOURFVg==
HTTP/1.1 401 UNAUTHORIZED
Content-Length: 25
Content-Type: text/plain; charset=UTF-8
Server: GeognoSIS/7.1.135.0 (Alpha)
WWW-Authenticate: Negotiate TlRMTVNTUAACAAAABgAGADgAAAAVwoniTAEcDtTrdXk4jgACAAAAAJYAlgA+AAAABgBxFwAAAA9EAEUAVgACAAYARABFAFYAAQAMAEQARQBWADMAMAA5AAQAHgBEAGUAdgAuAGMAYQBkAGMAbwByAHAALgBuAGUAdAADACwARABFAFYAMwAwADkALgBEAGUAdgAuAGMAYQBkAGMAbwByAHAALgBuAGUAdAAFABYAYwBhAGQAYwBvAHIAcAAuAG4AZQB0AAcACAAa39zYFwnKAQAAAAA
X-Cadcorp-GeognoSIS-Licence: {"Vendor Information":"Debug-only unlicensed version"}
0.52s
GET /ogcservice/wmts.impl?service=wmts&request=getcapabilities&version=1.0.0 HTTP/1.1
Accept: image/gif, image/jpeg, image/pjpeg, application/x-ms-application, application/vnd.ms-xpsdocument, application/xaml+xml, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-silverlight, application/x-shockwave-flash, *
So, I tried to reproduce these headers in the C# app. I did something like this:
webRequest = WebRequest.Create(url);
webRequest.Credentials = CredentialCache.DefaultCredentials;
((HttpWebRequest)webRequest).UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-GB; rv:1.9.0.11) Gecko/2009060215 Firefox/3.0.11 (.NET CLR 3.5.30729)";
((HttpWebRequest)webRequest).Accept="text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
((HttpWebRequest)webRequest).KeepAlive = true;
((HttpWebRequest)webRequest).Headers["Accept-Encoding"] = "gzip,deflate";
((HttpWebRequest)webRequest).Headers["Accept-Charset"] = "ISO-8859-1,utf-8;q=0.7,*;q=0.7";
webRequest.PreAuthenticate = true;
webResponse = webRequest.GetResponse();
doc.Load(webResponse.GetResponseStream());
The webresponse is not empty, but I cannot see anywhere the username and password of the current user, but I guess this is ok? I dont have this username and password in my hand, and this is the reason why I am using the defaultCredentials, in the first place...
The negotiation process gets interrupted on step 2 of the process with a "System.FormatException: Invalid length for a Base-64 char array." error.
These are the headers of the negotiation process between the server and the C# app:
GET /ogcservice/wmts.impl?service=wmts&request=getcapabilities&version=1.0.0 HTTP/1.1
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-GB; rv:1.9.0.11) Gecko/2009060215 Firefox/3.0.11 (.NET CLR 3.5.30729)
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,**;q=0.8
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Authorization: Negotiate TlRMTVNTUAABAAAAt7II4gMAAwAuAAAABgAGACgAAAAGAHEXAAAAD0RFVjMwOURFVg==
Host: localhost:4326
HTTP/1.1 401 UNAUTHORIZED
Content-Length: 25
Content-Type: text/plain; charset=UTF-8
Server: GeognoSIS/7.1.135.0 (Alpha)
WWW-Authenticate: Negotiate TlRMTVNTUAACAAAABgAGADgAAAA1woni33R9x/Rrb/E4jgACAAAAAJYAlgA+AAAABgBxFwAAAA9EAEUAVgACAAYARABFAFYAAQAMAEQARQBWADMAMAA5AAQAHgBEAGUAdgAuAGMAYQBkAGMAbwByAHAALgBuAGUAdAADACwARABFAFYAMwAwADkALgBEAGUAdgAuAGMAYQBkAGMAbwByAHAALgBuAGUAdAAFABYAYwBhAGQAYwBvAHIAcAAuAG4AZQB0AAcACACto1cBGwnKAQAAAAA
X-Cadcorp-GeognoSIS-Licence: {"Vendor Information":"Debug-only unlicensed version"}
They seem pretty similar to the ones that are sent by IE, except at this point I get an error:
0.56s
A first chance exception of type 'System.FormatException' occurred in System.dll
A first chance exception of type 'System.FormatException' occurred in System.dll
A first chance exception of type 'System.Net.WebException' occurred in System.dll
The thread 'Win32 Thread' (0x13d0) has exited with code 0 (0x0).
A first chance exception of type 'System.ObjectDisposedException' occurred in System.dll
A first chance exception of type 'System.ObjectDisposedException' occurred in System.dll
A first chance exception of type 'System.Net.WebException' occurred in System.dll
System.Net.WebException: The request was aborted: The request was canceled. ---> System.FormatException: Invalid length for a Base-64 char array.
at System.Convert.FromBase64String(String s)
at System.Net.NTAuthentication.GetOutgoingBlob(String incomingBlob)
at System.Net.NegotiateClient.DoAuthenticate(String challenge, WebRequest webRequest, ICredentials credentials, Boolean preAuthenticate)
at System.Net.NegotiateClient.Authenticate(String challenge, WebRequest webRequest, ICredentials credentials)
at System.Net.AuthenticationManager.Authenticate(String challenge, WebRequest request, ICredentials credentials)
at System.Net.AuthenticationState.AttemptAuthenticate(HttpWebRequest httpWebRequest, ICredentials authInfo)
at System.Net.HttpWebRequest.CheckResubmitForAuth()
at System.Net.HttpWebRequest.CheckResubmit(Exception& e)
at System.Net.HttpWebRequest.DoSubmitRequestProcessing(Exception& exception)
at System.Net.HttpWebRequest.ProcessResponse()
at System.Net.HttpWebRequest.SetResponse(CoreResponseData coreResponseData)
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.GetResponse()
at Cadcorp.GeognoSIS.Manager.NodeMiscServicesGMaps.SetupChildren() in F:\V71\SIS\Tools\GeognoSISManager\NodeMiscServicesGMaps.cs:line 140
The thread '_threadstartex' (0x108c) has exited with code 0 (0x0).
Does anybody has any ideas about this? Any help would be much appreciated!
best regards,
Jo
|
|
|
|
|
Ok, I start to thing this has something to do with the formatting of the string that the server is sending to the C# client (or maybe some illegal characters?)
This is an accurate description of the places where I'm getting error in my app:
at System.Convert.FromBase64String(String s)\r\n
at System.Net.NTAuthentication.GetOutgoingBlob(String incomingBlob)\r\n
at System.Net.NegotiateClient.DoAuthenticate(String challenge, WebRequest webRequest, ICredentials credentials, Boolean preAuthenticate)\r\n
at System.Net.NegotiateClient.Authenticate(String challenge, WebRequest webRequest, ICredentials credentials)\r\n
at System.Net.AuthenticationManager.Authenticate(String challenge, WebRequest request, ICredentials credentials)\r\n
at System.Net.AuthenticationState.AttemptAuthenticate(HttpWebRequest httpWebRequest, ICredentials authInfo)\r\n
at System.Net.HttpWebRequest.CheckResubmitForAuth()\r\n
at System.Net.HttpWebRequest.CheckResubmit(Exception& e)\r\n
at System.Net.HttpWebRequest.DoSubmitRequestProcessing(Exception& exception)\r\n
at System.Net.HttpWebRequest.ProcessResponse()\r\n
at System.Net.HttpWebRequest.SetResponse(CoreResponseData coreResponseData)
Does anybody know a way of looking into this string that is causing problems?
cheers,
Jo
|
|
|
|
|
Problem sorted!
It turned out there was a problem in the server, and it was *indeed* sending an invalid length string...
|
|
|
|
|
In window Form : I want to identify the row and colum of edit cursor .when I use movement key or mouse click ,i still know position of cursor (row and colum) .So what to do that .
Sorry for my english !
|
|
|
|
|
Well, before even going into the details, can you tell us why do you whant to do that?
May be a alternative/simpler approach can help you.
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
I have 1 problem and i want to learn how to do that
|
|
|
|
|
This might give you a little idea:
private void richTextBox1_MouseHover(object sender, EventArgs e)
{
Point _location = richTextBox1.GetPositionFromCharIndex(richTextBox1.Text.Length - 1);
MessageBox.Show(string.Format("{0}, {1}",
_location.X,
_location.Y));
}
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
Sorry , i want to identify the row and column of editing cursor .
for example : I paste a document to richtextbox end then i use "up key" or "down key" to move the edting cursor and then i know the position of editing cursor .
Please help me ! Sorry for my english.
|
|
|
|
|
Something like this would work but I doubt it is the best way to do it....
private void richTextBox1_KeyUp(object sender, KeyEventArgs e)
{
int totalLength = 0;
int line = 0;
int pos = 0;
for (int i = 0; i < richTextBox1.Lines.Length; i++)
{
if(i != 0) totalLength++;
totalLength += richTextBox1.Lines[i].Length;
if (totalLength >= richTextBox1.SelectionStart)
{
line = i + 1;
pos = richTextBox1.SelectionStart - (totalLength - richTextBox1.Lines[i].Length);
break;
}
}
label1.Text = "Line " + line.ToString() + "; Char " + pos.ToString();
}
|
|
|
|
|
Hi,
I haven't used it myself (I don't like RTB that much) but this looks like the right tool[^] for you.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Here the code programing network about receive message
<br />
private void Received(IAsyncResult iar)<br />
{<br />
NetworkStream ns = (NetworkStream)iar.AsyncState;<br />
int byteRead = ns.EndRead(iar);<br />
String sReply = Encoding.ASCII.GetString(m_byteData,0,byteRead);<br />
String sProtocol = sReply.Substring(0, 8);<br />
<br />
switch (sProtocol)<br />
{<br />
case "GETPRES ":<br />
if(timerSendMonitorDesktop.Enabled ==false)<br />
timerSendMonitorDesktop.Enabled = true; <br />
break;<br />
}<br />
}<br />
<br />
private void timerSendMonitorDesktop_Tick(object sender, EventArgs e)<br />
{<br />
MessageBox.Show("abc");<br />
}<br />
<br />
Help me!Thanks you
|
|
|
|
|
anhhuynokia wrote: Help me!
Help you do what exactly?
What issues are you having? what are you trying to do that dont work?
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
What type is the timerSendMonitorDesktop ?
I know the System.Windows.Fomrs.Timer requires you to call the Timer.Start() method.
So try timerSendMonitorDesktop.Start()
|
|
|
|
|
When you say "is not work" what does happen?
Does the code reach the Recieved method at all?
If you put a breakpoint at "if(timerSend...", does the code reach it?
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|