|
Hi Judah,
Many thanks for that! Damn quick reply.
The other language is no where near C# its an internal language called C/AL which is a bit like pascal\C, and is interperated at the time by the application. But it can handle COM objects
Many thansk again for the swift reply.
Tony
|
|
|
|
|
-- modified at 18:14 Monday 16th October, 2006
(fixed so changed as still have error)
Okay so I managed to make it build succesfully. But it still won't register. I still get the dllregisterserver entry point error.
This is the code, simple I know!
<br />
using System;<br />
using System.Collections.Generic;<br />
using System.Text;<br />
using System.Runtime.InteropServices;<br />
<br />
namespace CheckDate<br />
{<br />
[Guid("1AD0462D-4FA2-4072-B63B-8B1D88212389")]<br />
<br />
public class CheckDate<br />
{<br />
<br />
<br />
private int _day;<br />
private int _month;<br />
private int _year;<br />
<br />
public int day<br />
{<br />
set { _day = value; }<br />
<br />
}<br />
<br />
public int month<br />
{<br />
set { _month = value; }<br />
<br />
}<br />
<br />
public int year<br />
{<br />
set { _year = value; }<br />
<br />
}<br />
<br />
public bool checkDate()<br />
{<br />
DateTime newDateTime;<br />
string dateString;<br />
dateString = _day.ToString() + _month.ToString() + _year.ToString();<br />
if (DateTime.TryParse(dateString,out newDateTime))<br />
return true;<br />
else<br />
return false;<br />
}<br />
public void clear()<br />
{<br />
_day = 0;<br />
_month = 0;<br />
_year = 0;<br />
}<br />
<br />
}<br />
}<br />
|
|
|
|
|
I haven't done this in awhile, so my memory is a little foggy. A couple things jump out at me:
I believe you'll need an interface declared that defines the functionality you want available in COM. Something like:
[Guid("03AD5D2D-2AFD-439f-8713-A4EC0705B4D9")]
interface ICheckDate
{
void DoThis();
void DoThat();
}
Then have you class implement that interface. I think you'll need the ClassInterface attribute on your class as well. Your class declaration should look like this:
[ClassInterface(ClassInterfaceType.None), Guid("1AD0462D-4FA2-4072-B63B-8B1D88212389")]
public class CheckDate : ICheckDate
{
...
}
I'm a little fuzzy on this though whole .NET-to-COM interop, so take it with a grain (or generous helping ) of salt.
p.s. next time try <pre> tags around your code snippets.
*edit*
Looking at that article[^] again, it seems you need to call regasm tool to register the .NET assembly. I'd definitely check out that article and see for sure what needs to be done.
|
|
|
|
|
well, I tried that too, but no success. Doh.
<code>
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace CheckDate
{
[Guid("2BE56F71-BC00-4736-8D85-9A3C6438CDA7")]
interface ICheckDate
{
bool checkDate();
void clear();
}
[ClassInterface(ClassInterfaceType.None), Guid("1AD0462D-4FA2-4072-B63B-8B1D88212389")]
public class CheckDate : ICheckDate
{
public int day
{
set { _day = value; }
}
public int month
{
set { _month = value; }
}
public int year
{
set { _year = value; }
}
public bool checkDate()
{
DateTime newDateTime;
string dateString;
dateString = _day.ToString() + _month.ToString() + _year.ToString();
if (DateTime.TryParse(dateString,out newDateTime))
return true;
else
return false;
}
public void clear()
{
_day = 0;
_month = 0;
_year = 0;
}
}
}
</code>
|
|
|
|
|
Did you try running regasm on the assembly instead of regsvr32?
|
|
|
|
|
Hi Judah,
I did, but I need to ship the DLL out to another machine as well, so I am assuming they would need to use regsvr32. hence trying that.
<code>
Microsoft (R) .NET Framework Assembly Registration Utility 2.0.50727.42
Copyright (C) Microsoft Corporation 1998-2004. All rights reserved.
Types registered successfully
</code>
|
|
|
|
|
You'll need to register it on the target machine with regasm, I believe. .NET needs to be installed on the target machine too, so regasm will be there if .NET is installed.
|
|
|
|
|
I used the REGASM on my local machine, but I still can't see the custom control in my internal DB langauage.
Once registered, they normally show.
Any other way to test if its been implemented?
T
|
|
|
|
|
I have some old .NET-to-COM code along with steps to register it somewhere. I'll see if I can dig that up tomorrow.
p.s. as I understand it, regasm has an optional argument you can pass it to generate a tlb file from the assmebly. If you do that, can you use the resulting tlb file in regsvr32?
|
|
|
|
|
<code>
Checkdate.tlb is not an executable file and no registration helper is registered for this file type.
</code>
Thanks for all the help by the way I appreciate it!
T
|
|
|
|
|
If you use a tool like OleView or some other COM object viewer, your regasm'd dll doesn't show up on the target system? It should! :-p
|
|
|
|
|
Hi Judah,
I just downloaded oleview to see, and it is there
Just can't see it in my DB langauge. damn it. Oh and when I try to expand it in Oleview it complains at me
COGetClassObject failed.
The system cannot find the file specified.
severity: SEVERITY_ERROR, facility: FACILITY_WIN32($80070002)
T
|
|
|
|
|
Nooie, I'm afraid I've given you all the help I know how. Maybe someone else knows where you're going wrong. Yeah, AFAIK, doing regasm on the dll built with all the specs we just went over should work. I'm afraid I don't have any other ideas.
|
|
|
|
|
Is it possible to change the backgroundcolor of cells in a read only grid? The selected cell is gray (Control ), but niether of the color properties in the designer that are set to the color Control by default affect this color.
Is there a way to override the default behavior of selecting the contents of a cell when it's clicked in?
Can I right align the values in the grid instead of left aligning them?
|
|
|
|
|
I'm not sure about #1, but I'd say it's very likely you can override this by either implementing a custom cell type or by overriding the grid itself.
#2, this behavior is specific to the cell type, I believe. If you want different behavior, you'll likely have to implement a custom cell type that behaves differently when click inside its contents.
#3 I'm afraid I don't know.
This page[^] has some samples & whitepapers about the DataGridView control.
|
|
|
|
|
The DataGridView's a framework generation beyond what I can use while still stupporting my clients oldest PCs. Writing a custom cell's probably more effort than I can put into it now. It might be easier to just revert that control back to a listview.
|
|
|
|
|
I have some code that I moved into a background thread that takes a considerably longer time to execute then it does if it's done in the main thread.
When in a background thread the code takes 2 minutes to execute. When in the main thread it takes 4 seconds to execute.
This seems like it's way too much of an increase to be normal.
Any ideas of what I can try to bring this execution time closer to 4 seconds while keeping it in a separate thread?
|
|
|
|
|
No idea, but it's almost certainly due to a bug in your code; this would otherwise not happen. Can you post some relevant code snippets?
|
|
|
|
|
Judah Himango wrote: No idea, but it's almost certainly due to a bug in your code; this would otherwise not happen. Can you post some relevant code snippets?
<br />
...<br />
Thread worker = new Thread(new ParameterizedThreadStart(ThreadOperation));<br />
worker.IsBackground = true;<br />
worker.Start(dataobj);<br />
m_dlgThreadProgress.ShowDialog(this);<br />
...<br />
<br />
private void ThreadOperation(object obj)<br />
{<br />
DataObj dataobj = (DataObj)obj;<br />
new ThreadObj(this).TimeConsumingOperation(dataobj);<br />
Invoke(m_delegateCloseProgressDialog);<br />
Invoke(m_delegateListViewUpdate, dataobj);<br />
System.Diagnostics.Debug.WriteLine((DateTime.Now - m_dtStartLoadingTime).ToString());<br />
}<br />
<br />
I pass in "this" to the ThreadObj so it can Invoke operations to update the progress bar dialog. If you need any more code let me know...
|
|
|
|
|
I'm pretty sure this problem is home-grown, something like this doesn't happen regularly.
Perhaps you've introduced the problem with your inter-thread synchonization?
Please post some code, otherwise we won't be able to help you.
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
mav.northwind wrote: I'm pretty sure this problem is home-grown, something like this doesn't happen regularly.
Perhaps you've introduced the problem with your inter-thread synchonization?
Please post some code, otherwise we won't be able to help you.
See code in my reply above, but I also tried using a BackgroundWorker instead of a Thread and I'm seeing the same result...
<br />
...<br />
m_bwWorker.RunWorkerAsync(dataobj);<br />
<br />
private void m_bwWorker_DoWork(object sender, DoWorkEventArgs e)<br />
{<br />
ThreadOperation((DataObj)e.Argument);<br />
}<br />
<br />
private void ThreadOperation(object obj)<br />
{<br />
DataObj dataobj = (DataObj)obj;<br />
new ThreadObj(this).TimeConsumingOperation(dataobj);<br />
Invoke(m_delegateCloseProgressDialog);<br />
Invoke(m_delegateListViewUpdate, dataobj);<br />
System.Diagnostics.Debug.WriteLine((DateTime.Now - m_dtStartLoadingTime).ToString());<br />
}<br />
|
|
|
|
|
What happens if you do BeginInvoke instead of Invoke?
Also, when you used a background worker, you used ReportProgress instead of Invoke, right? (With BackgroundWorker, you ReportProgress which gets executed on the UI thread asychronously.)
|
|
|
|
|
Judah Himango wrote: What happens if you do BeginInvoke instead of Invoke?
Also, when you used a background worker, you used ReportProgress instead of Invoke, right? (With BackgroundWorker, you ReportProgress which gets executed on the UI thread asychronously.)
I changed all my Invokes to BeginInvoke in the LongOperation and outside of it with no change in execution speed.
|
|
|
|
|
What happens if you remove all Invoke and BeginInvoke calls?
|
|
|
|
|
Judah Himango wrote: What happens if you remove all Invoke and BeginInvoke calls?
Same thing, if it's called from within a worker thread it's quite a bit slower. I've even done some more timings where i take out the long process out of the method that takes too much time and there is still a noticable difference between threaded and non-threaded.
|
|
|
|