|
Alright,
My first born child to anyone who can sort me out. I have an ArrayList filled with objects called remotes. Remote is a struct, and in remote I wrote the CompareTo method to allow a binary search on the arraylist. This CompareTo method compares the remoteIDs, which is a field that I fill in as I populate the arraylist. The remoteID is from a database, it is unique, but not necessarily consecutive. So I may have three remotes in my arraylist of 30, 50, and 80. When I do a binary seach based on an object I populate, say I create a new remote, set its remoteID to 30, and do a binary seach on the arraylist, it works if the remoteID is close to the bounds of the array. So if the array length is 82, and my remote ID is 50, it finds the object and returns the index correctly. When I start getting nearer to the bounds of the array, say remote id equals 81, or even 85, being greater than the bounds of the array, it returns a negative number being one greater than the count of the array. So in this case a -83. Is it using the bounds of the array as min and max numbers, and therefore the algorithim bombs out do to the fact that my RemoteID numbers are outside those bounds? What can I do to resolve this issue? Any help offered would be greatly appreciated.
Thanks,
Ryan
|
|
|
|
|
I'm not quite sure I follow you right (I hate "run-on" paragraphs ) so let me ask a couple things. So, you implemented IComparable for sorting, right? This problem occurs when sorting? How about posting the source somewhere (if not long, just post it here)?
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
No, I implemented IComparible for the binary search function. The code is pretty involved, so if i posted it, i think it would make things difficult.
|
|
|
|
|
AFAIK you will need to call sort everytime u insert a new element. BinarySearch only works on sorted data.
leppie::AllocCPArticle("Zee blog"); Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.
|
|
|
|
|
Echoing leppie, the only way you can perform a binary search is if the elements are ordered. Otherwise, there's no way to partition the search space.
Binary search algo:
1. initial searchpos = midpoint of array
2. testvalue = value(searchpos)
3. if( testvalue > searchvalue )
searchpos = midpoint( beginningofarray, searchpos )
elseif( testvalue < searchvalue )
searchpos = midpoint( searchpos, endofarray)
else
you found your value
4. goto 2
[EDIT]Yeah, I'm aware of the glaring bugs in the above pseudocode...see below for explanation [/EDIT]
Not sure if this answers anything...I'm too burnt out to tell
Jeremy Kimball
|
|
|
|
|
|
Helo,
I'm developing a web page which need an ActiveX control,
I add the ActiveX control to the webform, and then I go to
the properties of the new object and put ID = Objeto1,
then I try to write in the webform Objeto1. nothing apear,
but i wrhite Objeto1.Method(); and when i try to compile
send me an error.
How I can add property the ActiveX control?. I need the
methods, properties and events of the ActiveX.
Levi
|
|
|
|
|
Are you wanting to add this as a server-side object (for data processing, etc.) or so the client (browser) sees it? If the latter is the case, you don't do anything on the server side. Embed it on the web page and rely upon client-side scripting like Javascript and VBScript. These are two distinct contexts that must be understood. The server processes the page which produces HTML. That HTML is downloaded to the client to display. Everything you see in a browser is resident in memory on the client.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
How Can we process a html document in windows application and display a html document in windows application
Thanx
Inam
|
|
|
|
|
What do you mean by "process". You mean like replace variables and what not? Just read it in with a TextReader or something similar.
To display it, the most common method is to embed the WebControl, the HTML rendering and default MSHTML handler for Internet Explorer (also dubbed Internet Explorer, even though that technically refers to iexplore.exe, which is merely a COM container for the WebBrowser control).
Open your Windows Form. Show the toolbox, right-click and select "Customize Toolbox". Under the COM tab, find the Microsoft Web Browser control and add it. Then drag this onto your form and start programming. VS.NET will automatically import the typelib for the WebBrowser2 control as an RCW (runtime callable wrapper). Do actually access the HTML DOM, you need to reference Microsoft.mshtml.dll, which is an RCW for the entire mshtml.dll native library on Windows (which the WebBrowser control actually hosts and provides default functionality for links and what-not).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
i was reading this:
http://www.codeproject.com/csharp/trayiconmenu01.asp
and it said to put this:
m_notifyicon = new NotifyIcon();
m_notifyicon.Text = "Hello, what's cooking?";
m_notifyicon.Visible = true;
m_notifyicon.Icon = new Icon(GetType(),"Icon1.ico");
in the "form object's constructor"
Where is that??
|
|
|
|
|
Um...if you don't know what a constructor is, you really need to read the product documentation (.NET Framework, VS.NET documentation, or any book on object-oriented programming!). You won't get far at all without knowing the basics of object-oriented programming. There's plenty of books on the subject.
A constructor initializes a class to make an instance. See the new NotifyIcon statement? Without a constructor (that took zero params), you couldn't create an instance of that class (object). Your form's constructor is like so:
public class MyForm : Form
{
public MyForm()
{
}
}
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
i want to make my richtextbox class inherited from system.windows.forms.richtextbox class, wich will show pages, pagenumbers and more...(how ms word print layout).
but i have no ideas to make this.
if you know how make this please help me
|
|
|
|
|
How can I call a OCX method into a WEB project? I try, but a unreferencial object error appear.
Thank you!!
aLeXs
|
|
|
|
|
Sounds like you didn't instantiate the control. It looks like you got a NullReferenceException? Just 'new it up' like every other class:
MyOCXClass ocx = new MyOCXClass(); Adding a COM control to your .NET projects in VS.NET automatically creates a Runtime Callable Wrapper (RCW), which is what MyOCXClass is (assuming your OCX is named "MyOCX"). It also imports all the interfaces, enums, structs, etc. that are defined for the object(s).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Has anyone noticed anything strange happening when you try to use the ref statement to pass a parameter while in a sub-thread?
Here's what I did:
<br />
public void ThreadProc()<br />
{<br />
byte[] data=new byte[7];<br />
data[0]=0;<br />
data[1]=0;<br />
data[2]=1;<br />
data[3]=0;<br />
data[4]=1;<br />
data[5]=7;<br />
data[6]=7;<br />
<br />
chip1.WriteSPI(ref data[0], 7);<br />
}
where ThreadProc is called when I start a new thread:
<br />
thread1=new System.Threading.Thread(new ThreadStart(ThreadProc));<br />
thread1.Priority=System.Threading.ThreadPriority.Lowest;<br />
thread1.Start();
chip1.WriteSPI(ref byte datain, datasize) calls a COM object method that writes a stream of bytes on the USB port to a device downstream. It uses the reference as a pointer to the byte array.
All of this works fine in the main part of my app, but when I try to put it in a separate thread it writes garbage data to the port (actually it keeps writing the same garbage data every time). Has anyone done anything like this? Please feel free to point out my gross ignorance where appropriate.
Thanks
JR
|
|
|
|
|
Is your COM object implemeneted as an STA or an MTA? If it's an STA, threading it can lead to unknown results. Marshalling could also be the culprit. If you're not marshalling the data correctly, its representation in the other context might not be correct and would produce garbage (right memory, wrong structure).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
My COM object is not implemented as an STA.
so if it's marshalling, what can I do? (I know there probably isn't a short answer)
thanks.
|
|
|
|
|
Instead of importing the typelib automatically, you may have to define your own interface in .NET (that which reflects the class interface of your OCX), putting the appropriate marshaling attributes (MarshalAsAttribute ). See that class (and the System.Runtime.InteropServices namespace for more details (and it'd be good to take a quick glance before proceding).
Question, though. Are you trying to pass the first byte array element as a reference, or do you want to pass the entire array. The way you're doing it means that you're passing the address of the first element and this will definitely requiring marshaling. If you want to pass the whole array as a ref, use ref myByteArray as a parameter instead. .NET will take care of a lot of things for you, including stuff like this.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I want to pass the entire array, but what data type will my COM object be expecting if I pass ref bytearray ?
right now, the prototype for my COM method is:
STDMETHODIMP CUSB::WriteSPI(unsigned char* datain, int size)
so, when C# gets a hold of that, it takes the pointer as a ref byte
in other words, what is the C++/COM equivalent of a ref to an array?
|
|
|
|
|
First, an array is always a reference type. While some examples use ref with arrays, it's really only necessary for value types (int , long , byte , etc.) Passing a reference type results in the address passed to the native function.
For your interface, though, you'd want to write your method to that functions like so:
[Guid("...")]
public interface IUSB
{
void WriteSPI(
[MarshalAs(UnmanagedType.LPArray,SizeParamIndex=1)]byte[] array,
int size);
} This will marshal the array as the address to the first element, which is what you're wanting to do.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I understand, but C# still sees the unsigned char* from my COM method as a ref byte so how can I get around that?
sorry to keep bugging you.
|
|
|
|
|
Hmm, it's usually right...but not always the easiest to implement. It would make sense, since ref'ing the first element would return the address of the array, but as you can see...it's not working.
What I was referring to was actually defining the interface yourself and not using the interop assembly that's generated automatically. Especially for small typelibs or for typelibs which you only need a couple of things (like many do for mshtml's typelib), it's just easier defining the interface with the right attributes and method placements (for IUnknown interfaces, order of the methods is important; for IDispatch interfaces, using the DispIdAttribute with the correct ID is important). You can still instantiate the COM object through the interop, or derive a class from AxHost and override the necessary things, also implementing your interface, or using various methods in the Marshal class or Type class, and set the reference to a variable defined as your class interface. Access the methods from the interface (as in all COM you should, anyway).
Still, though, that method signature should be right. When you say jibberish, what exactly do you mean?
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
When I said it was putting out garbage data, when I call
WriteSPI(dataarray, size) I was looking at the output in bytes and I would get:
00 00 AA 00 size 00 ...
so the size value was being sent in the part that was supposed to be the data, the first three bytes of data was always the same though, no matter what I sent.
Are you saying that I can write a separate interface for my COM object in C#, that will override the one that was automatically generated when I compiled the C++ code for the COM object?
If so, I didn't realize you can do that. If I specify the GUID as an attribute for the object, it will be able to find it?
hmmmm...
|
|
|
|
|
This definitely sounds like a marshaling problem. Seems like data about the array is being sent when you want the array data since the bytes should be the same on both.
You shoud read Advanced COM Interop in the MSDN Library. Basically, you're interface is just a way to access the class. In COM, you treat every object through it's interface by QI'ing (QueryInterface) for the interface that the class implements. In .NET this is acheived by merely casting.
You can define the interface in your project regardless of what is in the interop assembly, yes. As long as the method signatures are marshalable and similar (proper number of params) and use the same return types (should all be void unless PreserveSignature is true , which then you use int to represent an HRESULT). Just instantiate your COM class and cast it to the interface you redefined (remember, use the same GUID for the interface in the GuidAttribute and keep all that stuff the same I said in the previous post) and you should have a valid reference to your object through that interface (again, it's like calling QI, which doesn't care about qualified names like .NET does).
I'm not sure I'm explaining this as easily as possible, but read that section in MSDN (or perhaps start with the more basic stuff that comes before it). COM interop is powerful but is also is a beast to tame.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|