|
Maybe somebody could help me?..
I've build in .NET C# kind of wrapper object to my old COM server (it simply contains that COM server interface pointer inside and exports almost the same properties/methods outside redirecting all calls to that COM interface). Definitely, in order to use COM server in .NET I've generated interop for it. My wrapper resides in its own assembly which uses in runntime (as I supposed) that interop but, the problem appears when I compile module which uses my wrapper: C# compiler asks to add to reference that COM interop also because it can't find definition of that internal COM interface!?. My question is why in compile time C# compiler has to know about internal implementation of my assembly ? I do not export any interface or type from that COM interop, moreover the purpose of this wrapper is to hide COM implementation !.. Is it any way to include that interop in my assembly?.
Thanks in advance, Vlad.
|
|
|
|
|
Because the interop assembly is a dependency of the assembly containing your wrapper, which is a dependency of the assembly using the wrapper. Because the wrapper uses the interop assembly internally, it must be able to reference it in order to compile. Even if both of these assemblies are compiled and added as .NET references (as opposed to project references when using all of them in a single solution), the interop assembly is required in order to load the wrapper assembly. It's also possible that you might be using a Type from the interop assembly as a publicly exposed param, return type, interface, or struct so that would force a dependency resolution.
Basically, any dependencies - whether direct or indirect - must be resolvable when compiling and when running, so long as the Type is access (which foces a JIT compilation).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath, thanks for reply...
Look, I've cheked my assembly code one more time and see no Type from the interop assembly publicly exposed... The compiler generates error on my wrapper construction (new instantination) line of code and wants to include COM interop in oder to get iterop-wrapped COM interface type which I use internally (as private data member) in my C# wrapper class and in its contructor I create new instance of that COM class...
I simply do not understand something: is it so different from C++ where during compile time it is enough just function declaration... or (just another thought ) it is so similar to C++ inline/template functions where compiler has to read the code of the function in order to generate inline/template implementation?.
Thanks, Vlad.
|
|
|
|
|
C/C++ links against the addresses of functions, where .NET compilers must load the assembly in order link to Types and members. If that assembly has dependencies, those dependencies must be resolved.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks, from now it's understandable
Just last question... Can I put two or more interops/assemblies together into one file?
Thanks, Vlad
|
|
|
|
|
Not two assemblies, no, but you can combine zero or more modules in an assembly. A module is the code without the metadata that makes up an assembly. In order to do this, you'd have to use ildasm.exe to disassemble both assemblies, combine the two IL files from each module (from each assembly, paying attention to how IL is formatted), then use ilasm.exe to reassemble after adding the assembly attributes from one assembly to the IL for the other, new assembly that you're creating.
Another way is to just define the COM interop classes, interfaces, etc. yourself, which Microsoft commonly did in the base class libraries. Make sure you understand marshaling and COM interoperability, though. You can learn a lot by looking through the System.Runtime.InteropServices namespace and several other sections of the .NET Framework SDK.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I'm working on a little project for school and I'm having a little problem with selecting a button.
I have some buttons and I have to detect which 2 buttons I just clicked so I can compare the values in it. How do I do that?
I can compare the two values, so that's not the problem, I want to know how to select two unknown buttons.
My code looks a bit like this
<br />
int comp1;<br />
int comp2;<br />
<br />
Button btncompare1;<br />
Button btncompare2;<br />
<br />
btncompare1=button1;<br />
btncompare2=button2;<br />
<br />
comp1=Convert.ToInt32(btncompare1.Text);<br />
comp2=Convert.ToInt32(btncompare2.Text);<br />
<br />
if(comp1>comp2)<br />
...<br />
<br />
I hope you understand my problem!!!
Thanks
|
|
|
|
|
What about using two global variables (or an array, even better), and a counter. Then, when one button is clicked, the reference to the instance is saved in the first position, and when another button is clicked, it is saved in the second. Like this:
public class MyClass
{
private Button[] _buttons = new Button[2];
private int _counter = 0;
public MyClass()
{
MyButton1.Click += new EventHandler(Button_Click);
MyButton2.Click += new EventHandler(Button_Click);
MyButton3.Click += new EventHandler(Button_Click);
}
private void Button_Click(object sender, EventArgs e)
{
_buttons[_counter] = (Button)sender;
_counter++;
}
}
Instead of manually assigning the events to your buttons in the class' constructor, you may want to use the Form-designer to do that. Just copy-and-paste the name of the method that handles the event in the field next to 'Click' on the 'Events' tab of the propertygrid of your buttons.
Don't forget to reset the counter (_counter = 0 ) when you're finished, or add a check to see whether _counter > _buttons.Length - 1 , then:
if (_counter > _buttons.Length - 1) _counter = 0;
|
|
|
|
|
Ok thanks it works now!
|
|
|
|
|
When I open my printPreviewDialog my Document shows fine in the dialog, but when i click on print it prints only the Headers of the document. Does anyone know what could be wrong?
|
|
|
|
|
please let me know a way to use adobe libraries in C# programes to accomplish conversion to pdf.
|
|
|
|
|
I've read that the Adobe libraries, even in their current version, are unwieldy and not very developer-friendly. There are several vendors that publish COM/ActiveX/.NET libraries for converting/creating PDF documents. I've used ActivePDF with success, and colleagues have used others equally successfully. Some are even advertised here on CP, if you hang around long enough.
|
|
|
|
|
yes, i too have used pdflib but i will have adobe acrobat installed, so my client doesnt prefer to buy other third party software. so i should use only adobe libraries. got any way out
|
|
|
|
|
I know there was a recent article somewhere... but I cannot remember where just now. Another article on www.west-wind.com dealt with this, however the code samples are in Visual FoxPro; the principals are the same, but you might go bald trying to re-work VFP into C#...
|
|
|
|
|
There is a tool called tallpdf I have used for convertion of pdf. This component is fully .NET compatible and the information is available in www.pdfzone.com/toolbox/TallPDF.html.
|
|
|
|
|
Many of the PDF converts to which John referred are royalty-free, meaning the client won't have to buy anything (unless you are writing this for a specific cient as part of a contract or something similar).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
hi..theres a software called ghostsript that can convert from doc to pdf thats a open source and its free..
thank you
|
|
|
|
|
I am using VisualStudio.NET 2002 with .NET Framework 1.0 Actually i am developing a program in which i have to use Browser Control. I have used it on a control which facilitate me in providing wizard. Actually it is a wizard control on which i have used WebBrowser Control. Now i have start it both bu using Debug and without debu it is alright. Now i have created a form in which i call this wizard. Now if i run this program without using debug it will run alright but if i run it with start using debug it will give me error that cannot instantiate Active X control. What can be the problem please guide me
ThanX in advance
Regards
INAM
Inam
|
|
|
|
|
How do I declare a class used for utility that I do not have instantiate everytime I want to call a method from it. I have tried static this and void that, but can not seem to get it write. I know the prof mentioned it in a class I attended, but stupid me I did not write ti down.
thanks
rod
bigmansoftware.com
|
|
|
|
|
Any class can have static methods. Just create a class (e.g. MyClass) and add static methods to it. For example, suppose you wanted a method that you'd use to strip characters off the end of a string. You might write something like:
public static string ShortenString(string s, int len)
{
if( s.Length <= len )
return "";
return s.Substring(0, s.Length - len);
} Then, you could call the method by writing:
...
string sNewString = MyClass.ShortenString(sOldString, 2); Notice that MyClass is never instantiated. (Internally, I believe a 'static' instance is created.)
Tom
|
|
|
|
|
Oops your right I was thinking of the case of static variables in the class which would be constructed even when calling a static method. It's too late I should be asleep.
|
|
|
|
|
Next version of C# has "static" classes, which means that they contain no constructors or instance members:
public static class BoogsUtils {
public static int ComputeStuff() {
...
}
}
|
|
|
|
|
boogs wrote:
which means that they contain no constructors
No instance constructors, that is. Static constructors are still allowed, which are guaranteed to run only once per AppDomain .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Consider the following code:
a) ...
string str = richTextBox1.Text;
bool b = richTextBox1.CanUndo;
...
b) ...
int nLength = richTextBox1.TextLength;
bool b = richTextBox1.CanUndo;
...
Both a) and b): CanUndo always returns false, regardless the text has been modified (run-time).
It seems that any call to the Text, TextLength... property will clear the undo buffer. Thus it makes difficult to implement a context menu (Undo, Cut, Copy, Paste, ...) for the RichTextBox control.
Is this a bug of the RichTextBox control, or does I miss something? Note that the TextBox control does not encounter this problem.
Thank you in advance.
|
|
|
|
|
Zembaliti wrote:
Both a) and b): CanUndo always returns false, regardless the text has been modified (run-time).
According to the documentation, the TextBoxBase.CanUndo property indicates whether or not you can undo the previous operation. In both of your instances, you are not performing operations directly on the RichTextBox , but accessing two of its properties so it should return false.
- Nick Parker My Blog
|
|
|
|