|
Thanks for your reply, Heath ...
Heath Stewart wrote:
You forgot step 4: run regasm.exe on your .NET assembly to register it as well.
Doesn't this mean I have to recompile the VB6 COM (yes, you were right) DLL again? Before you wince, please read my next few lines ... i wasn't being modest when i said "newbie"
Heath Stewart wrote:
Just out of curiousity, why expose the .NET assembly as a COM server, then wrap that with another COM server written in VB (by which I assume you mean VB6)? Why not just let COM clients reference the CCW?
Ignorance. Plain and simple.
When I got into this sub-sub-task of a much larger project, all I knew was that our coding team had something written in .Net that needed to be connected to something that knows how to call VB6 COM components. I sent out a few emails for help from several people without much response and then ran some experiments (even though they were designed and conducted out of the same ignorance mentioned above, plain and simple ) and finally came to the conclusion that the setup I had was the setup I needed. Basically as soon as it worked, i stopped experimenting.
I would certainly appreciate more input, if it's not too much to ask, on this specific issue and how it can be improved.
if this isn't the forum for what might become a painful series of questions and obvious answers, feel free to email me directly at sherif@amgando.org
again, thanks.
sherif
|
|
|
|
|
sherif wrote:
Doesn't this mean I have to recompile the VB6 COM (yes, you were right) DLL again?
No. When you compiled the assembly, if GuidAttribute s weren't used the internal GUID of the type that is generated at compile-time is used and will not change so long as you don't recompile the project. If you do, then you will need to re-add the typelib to the VB COM DLL and recompile it. This is another good reason to use the GuidAttribute for any COM-visible (read about the ComVisibleAttribute in the .NET Framework SDK) type. Class GUIDs (CLSIDs) should almost never change, and interface GUIDs (IIDs) should change from version to version (which means that interfaces - once published - should never change definitions; just inherit from the old interface with a new one and implement the new interface as the first interface for your class).
If you're looking to improve your COM interop skills, I suggest you pick up a good book on COM interop with .NET. I know that Microsoft Press[^] has one or two (I don't know how good they are - I learned all this through many years of experience with COM and as many years possible with .NET) and I'm betting there's a few more from other publishers you can find on Amazon[^] or something.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Anyone know how to set the Window class name for the main form of a Windows Forms .Net application? By default, they get class names like "WindowsForms10.Window.8.app3" -- I searched through all the files in the project and can't see where that's coming from. I didn't see anything in the base Form or in the Application object that does it, either...
Unfortunately, the overloaded nature of the words "window" and "class" make searching the help herculean task.
I need to have a well-defined class name (not the semi-random one that is autogenerated), so that I can find the app at runtime with FindWindow(); since the titlebar may be localized and may have additional stuff (like "My Localized AppName - Current document name.ext"), I would rather use a class name which could be more dependable.
Matt Gerrans
|
|
|
|
|
The "semi-random" one is not actually random - if you specify a registered window class. The window class is actually used in well-defined pattern. If the control does not have a window class associated with it, then it becomes random (though the basic pattern is still used).
Just like with VC++, MFC, etc., you need to either use a window class that is already registered (like Static, Button, etc.) or register your own a la RegisterClassEx , which uses the WNDCLASSEX structure. You can P/Invoke this easily enough.
Register the class (with a classname of your choosing, so long as it doesn't already exist) once, then override CreateParams in your Control derivative and set the CreateParams.ClassName as well as any other extended, window, or class styles you want.
Also, if you're merely looking for your application, you might consider enumerating Process.GetProcesses (which can also gets the processes given an executable name). Using the Process class's properties, you can discover additional information. If you need an HWND at any point, just use Process.MainWindowHandle .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi Heath,
I'm not clear on how you can change the CreateParams of the app's main form, since it is a protected member of the Control class, which is a few bases up the hierarchy from the Form class. Are you talking about creating a derivation of Control and replacing the main form with it?
I had considered the Process stuff, but was worried it wouldn't work with limited user accounts. However, I've just tried that and it works fine. I didn't know (or expect) that it had that MainWindowHandle property, either; that works out excellently; in fact, it looks like it is quite easy to get all the useful process and window information from the Process object (unlike in the Windows API, where it is a bit more complicated to connect processes information to window information). I think I'll go this route and be able to take care of what I need to do by using the process list.
Thanks Heath!
Matt Gerrans
|
|
|
|
|
Gerrans wrote:
I'm not clear on how you can change the CreateParams of the app's main form, since it is a protected member of the Control class, which is a few bases up the hierarchy from the Form class.
By extending the Form class with your own class, then override the CreateParams . If you want to just change a style, you typically get the base.CreateParams , modify, and return it; but in your case you're changing the class name - a pretty big change. Construct your CreateParams , change the styles and class name, etc., then return it.
Gerrans wrote:
I didn't know (or expect) that it had that MainWindowHandle property
You should browse through the Class Library documentation in the .NET Framework SDK. It's not like you have to memorize everything, but you should recognize a naming pattern that Microsoft sticks to about 98% of the time (according to FxCop). That makes it easy to find what you need, especially if you have some idea of what to look for.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have a VB.Net Windows service that needs to access a network drive. The code works as desired as a console app on the server but fails on the network share access as a Windows service. I have used both the Local System account as well as the local admin account to run the service. Same results both times. In ASP.NET I know the work around is to use Identity Impersonate in the web.config file but this is a Windows app not a web app. Any suggestions are appreciated and I apologize for the cross post.
"Your destiny lies before you, choose wisely."
|
|
|
|
|
You must either run under a domain account (and account that works on the domain and has permissions to that folder) or configure the user account which the service runs under using the same username and password (a trick useful on workgroups). Both the local administrator and local system accounts are local accounts.
The reason impersonation works is because, using a domain, the user's credentials are used which would be a domain account. Same for when you run your console application - it's running with a domain user's credentials.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
I'm currently trying to localize a .Net project. that means I need to use localized resources like stringtables and Bitmaps for german and english.
Following a localization sample delivered by VS, I succeessfully localized string-resources using the resgen and afterwards the assemblylinker(al.exe) tools.
Unfortunately, using the al-tool to localize bitmaps failed.
Does anyone have ideas or examples with which parameters to call the al.exe to use localized Bitmaps and how to use the bitmap-resource via GetManifestResourceStream() or something?
Thanks,
klawipo
|
|
|
|
|
The easiest way is to persist the images in ResX files (typically encoded in base64 - just set a BackgroundImage for a control and look at the form's/user control's .resx file "under" the file is you show all files in your project for an example). This allows you to use the ResourceManager which already takes care of the satellite assemblies for you; otherwise, you can use Assembly.GetSatelliteAssembly (calling it on an Assembly reference that is the primary assembly using the same assembly name but a different culture) and then call GetManifestResourceStream from that. If your primary assembly (the one with IL modules in it - the code that is executing) contains that culture (if you use the assembly-level NeutralResourcesLanguageAttribute ) or if no satellite assembly is found, and exception will be thrown so then grab the resource out of the primary assembly.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
i have 2 modules (exe) and i'm serializing a certain object with one module and i want to deserialize it with the other one..
but the framework throws an exception coz the assembly is not the same one it was serialized from..
any clue ??
thanx
shakoosh
|
|
|
|
|
I had a similar problem in the project I'm working on now. You need to ensure that the type that is being serialized exists in both assemblies. For example, say that you have the following setup:
ASSEMBLY 1:
- Module1.cs
ASSEMBLY 2:
- Module2.cs
And assume that each of those files has the code for some class Foo in it. Even if the code for Foo is byte-for-byte the same in both files, the framework will throw an error when attempting to deserialize because it's trying to instantiate the assembly in which the object was first created. The important fact here is that it's extremely difficult to separate a class from its containing assembly.
The solution that I ended up implementing:
ASSEMBLY 1:
- Module1.cs
- References [ASSEMBLY FOO]
ASSEMBLY 2:
- Module2.cs
- References [ASSEMBLY FOO]
ASSEMBLY FOO:
- Foo.cs
Here, simply remove the code for Foo from Module1.cs and Module2.cs, putting it into Foo.cs in a different assembly instead. If you reference ASSEMBLY FOO from both modules, the framework will now correctly locate the required assembly and deserialize the class.
There may in fact be an alternative method to implementing this, but this is the most straightforward method that I know of. It's also the one that worked for my project.
|
|
|
|
|
I have two .net applications (windows and web applications)
Both these applications use class from dinamic loaded .dll
How could I obtain the name of current application configuration file inside this .dll class?
Thanks.
|
|
|
|
|
AppDomain.CurrentDomain.SetupInformation.ConfigurationFile
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
The situation is that:
I write a master application. The master application contains several dll class component. I would like to implement the master application such that if there is a new dll class component install to the master application, the master application can detect the new component automatically without changing the master application. How do I implement it?
Thanks!
p.s (I am using C#)
|
|
|
|
|
You could track the last date it updated, and any newer files in the folder would get processed.
"For all of our languages, we cannot communicate" - Christy Moore, Natives
|
|
|
|
|
Is there any possibility to save Bitmap as JPG, however
with better quality than allows the following code :
...
encoderParameters.Param[0] = new EncoderParameter(Encoder.Quality,100);
//100 => maximum possible
foreach( ImageCodecInfo encoder in encoders ) //PERF OPT
{
if( encoder.MimeType == "image/jpeg" )
{
img.Save(stream,encoder,encoderParameters);
}
}
When saving images with maximum possible quality I get files that
are about 80% of size of image produced by Adobe Phooshop,
even with 10 (scale 1-12 ) quality (!)
It was somewhat about 160 kB, versus 200 kB, and of course,
the difference had been evident. The difference was visible
due to the fact that on the original image some lines and polygons
along with text were drawn. And these require quite a good
compression quality.
Sombody might say that I should save images as GIF or PNG, however
these do not provide as good compression ratio as JPEG does, even
when saving JPEG with the best quality (size increases)
(best JPEG by PhotoShop == 320 KB, best by framework == 160 KB,
PNG = 770 KB)
When saving image as JPEG with photoshop, user is able to choose
compression level (that seems to be "wider" than what framewotk
provides) and is able to choose from "Format options" that are
following: BaseLine, Baseline-Optimized and Progressive.
Is there any way to make the same work in GDI+ ?
But the main question remains : How to save image with quality
better than that from the above code example.
Thanks
Michał Januszczyk
|
|
|
|
|
I have a .NET DLL that has the following inheritance structure (each object inherits from the object above it):
<br />
BaseObject (VB6 COM DLL)<br />
COM Interop DLL (.NET)<br />
Abstract BaseObject (.NET)<br />
Abstract BaseObject2 (.NET)<br />
Concrete Object (.NET)<br />
To complicate matters, the Concrete .NET Class needs to be accessible from COM. I have set the appropriate attributes to make this happen, and everything works fine on my machine, and some others too.
To register on another machine, I use RegAsm. However, on some XP machines, regasm is failing, with the error:
<br />
RegAsm error: Could not load type XX.XX.AppBase from assembly XX.XX.XX, Version=0.9.1616.28364, Culture=neutral, PublicKeyToken=null because the format is invalid.<br />
where XX.XX.AppBase is the first abstract base object. All machines are running .NET 1.1. I have tried to work around the problem by using .reg files to register the DLL, but that just defers the error message until the application tries to use the object.
Has anyone any ideas on how I can resolve this, or what causes it?
|
|
|
|
|
Sometimes I had similiar problems using RegAsm.
I don't know whether they help, but I have a few advices:
-Clear all Registry Entries made from previous attempts to register your Assembly (search the registry e.g. for the dll-names or UUIDs if any are given in your Code).
-If not already done, type an unique Versionnumber in 'AssemblyInfo.cs' (Important: Don't leave any '*' in the Versionnumber. The '*' shall cause the VS to generate a Versionnumber. I think it's the Buildnumber. But this simply doesn't work correctly, s.t. regasm may try to register a seemingly older version over a newer one.)
- If it still doesn't work:
Try to 'export' as few symbols as possible. That means (in C#): Use 'public' only on functions that are used by other dlls or via com (e.g. implemented Interface-functions must be public).
Use 'internal' for other functions instead.
As far as I understood, public in C# is for com like dllexport in C.
Please tell me if any of the advices helped.
|
|
|
|
|
The problem turned out to be that my DLL exposed an ADO recordset. This was not a problem on machines with Visual Studio.NET installed, because they have ADODB.DLL in the GAC. However, most user machines do not. So the solution was to copy ADODB.DLL from my local machine (C:\Program Files\Microsoft.NET\Primary Interop Assemblies\ADODB.DLL) to the target machine, and then install it to the GAC (gacutil -i ADODB.DLL).
|
|
|
|
|
Hi. I’m thinking about building a general purpose high score xml web service to use in my games. I’m currently working on the Pocket 1945 project, a classic shooter for the Pocket PC. The project can be found at http://workspaces.gotdotnet.com/pocket1945, and an article about the project can be found at http://www.codeproject.com/netcf/CfPocket1945.asp. The article was submitted for the Code Project .NET CF competition, so if you think the project sounds cool, please vote.
So, my web service problem is: how do I make the high score service “secure”? I mean, how can I be sure a method call is coming from a registered game, and not some one trying to fake the score? I was thinking along the lines of strong named assemblies that you register in a database and validate the request and see if it’s a registered assembly posting a new score. But, then again this is only SOAP calls that could be tempered with?
I’m open for any suggestion. How have other people solved this problem? Is remoting an option?
Thanks!
|
|
|
|
|
Hi, I have a major problem with the CallContext when hosting a MarshalByRef Object in the IIS. The problem occurs when the executing method in the IIS throws an exception. The effect is that the LogicalCallContext in the ResponseStream is always the same as in the RequestStream.
My use case is the following: In the CallContext I carry a Transaction Context. At server side this Transaction Context is set or removed. If no exception occurs everything works. But in case of a exception, the modified context is not returned to the client.
Furthermore I tested this scenario in a Windows Service Host (tcp channel with binary) instead of IIS (http channel with binary or soap). In the service host everything works fine, especially with the exceptions. Is this a bug in the http channel in connection with the IIS? I found nothing about it in other Message Boards or newsgroups.
I tried it with SingleCall or Singleton objects.
Thanks in advance for your help.
|
|
|
|
|
How would I register a new file type (file type name, extension, and icon) for my apps with Windows using .NET? Thanks is advance!
Happy Programming and God Bless!
Internet::WWW::CodeProject::bneacetp
|
|
|
|
|
Hi,
I guess you are asking how to register a new file type during setup of an application.
What I know is if you are making a deployment package for your project then you can do customization on registering new file types with extension and even define custom action on the same.
To do that, in your setup and deployment project use the "File Types Editor" which is the 3rd ICON on the top bar of solution Explorer window.
For more information on how to go about it in the editor please refer to the following URL :
Setup and Deployment Customization
Hope itz useful...
regards,
Aryadip.
Cheers !! and have a Funky day !!
|
|
|
|
|
Thanks for the information. Actually, I was wondering how to do it programmatically. Anyone have any ideas?
Happy Programming and God Bless!
Internet::WWW::CodeProject::bneacetp
|
|
|
|
|