Thanks mate, figured it out on my own just as you posted
I'm just going through the Platform SDK documentation and converting anything I come across to C# COM. No particular purpose really, just learning about it. Very interesting, and i'm getting to grips with it quite nicely bar this small hickup.
It won't, so long as you don't cause an overflow. While the -1 (Int32) is 4,294,967,295 (UInt32), the number is still 0xffffffff. It's not uncommon to use ing instead of uint for parameter types like DWORDs. Even Microsoft does it when manually declaring COM interfaces that they use internally (or those few in System.Runtime.InteropServices that you can use).
Your TestClass has no constructor, so the framework makes a default one for you. It has to call the base contructor. The BasicClass has no default constructor because you defined a constructor with an argument.
publicclass TestClass: BasicClass
// Create a default constructor that explicitly// calls the existing basepublic TestClass() : base("")
// Create a default constructor in the base class.public BasicClass()
this.name = "";
public BasicClass(string name)
this.name = name;
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?.
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).
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?.
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.
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
//the text in my buttons is a number!<br />int comp1;<br />
int comp2;<br />
Button btncompare1;<br />
Button btncompare2;<br />
//Here's the problem! this is the only way I can select buttons<br />//but I have to select them by a click.<br />
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:
// Initialize a new array with a length of two (thus index 0 and 1):private Button _buttons = new Button;
privateint _counter = 0;
// Handle the events of your buttons.public MyClass()
MyButton1.Click += new EventHandler(Button_Click);
MyButton2.Click += new EventHandler(Button_Click);
MyButton3.Click += new EventHandler(Button_Click);
privatevoid Button_Click(object sender, EventArgs e)
// Assign your button to the array,
_buttons[_counter] = (Button)sender;
// and increase the counter by 1.
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:
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.
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#...
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).