How to use multiple idl files in ATL (COM) Project for .Net C# VS 2012 - visual-c++

I'm new to C++/COM. I have created a ATL COM Project with a callback mechanism to send messages to managed side. It has one idl file (sample1.idl) which expose 'n' number of methods, hence managed environment can access it. Now i would like to add another .idl(sample2.idl) file to that project.
.tlb is created for both sample1 & sample2 and build succeeded. On browsing the .dll , I couldn't find the sample2.idl related stuffs. I suspect that .tlb generated from ‘sample2.idl’ is not reflected in the .dll.
Can we have more than one IDL’s in the ATL (COM) project ?

The default for ATL, as with many native build environments, is to embed the type library as a resource in the DLL. Something you can see in Visual Studio (retail edition required), use File + Open + File and select the DLL. Open the "TYPELIB" node, you'll see one type library with resource ID #1. This is the one that Visual Studio sees when you use Add Reference.
Most any build tool that consumes type libraries will only ever look for that one resource. Visual Studio is no exception. It also can encode only one type library in its project files. You perhaps can make it work by selecting the 2nd .tlb file with the Add Reference dialog. Albeit that it is very likely that you'll now get exposed to more problems in your ATL project, like forgetting to register that 2nd type library in your .rgs file.
Very hard to give proper advice without any hint what that second IDL file might contain. Stay out of trouble by merging them or by using the existing support in IDL to import other .idl files or type libraries.

Related

How to take care the source from being stolen?

I'm using visual studio 2012 and SVN (tortoise) repository. I want to block some developers access to some source files, but I need the solution project compile ok. So I can't quit any file from it, and I don't want to use compiled dll. I want to know if exist some software /plug in / app that to controls some access permission to view/get files into VS. Any Idea ?
You could obfuscate the source code. (e.g. give variables cryptic names)
If this is an option, take a look at this thread.

How does Visual Studio process the App_Code folder specially?

How does Visual Studio process the App_Code folder when a change is made or detected in it? Not IIS or ASP.NET.
I want to gain a better understanding of why Visual Studio freezes for long periods of time whenever I save a code file inside a large App_Code folder of a website project. Alternatively, I could ask: why does Visual Studio not exhibit these same freezes when processing a file inside a class library that is equally large?
Ideally I would like to see official documentation cited from Microsoft of the issue at hand of processing the App_Code folder in Visual Studio and what happens that differs from processing a class library for example.
The App_Code folder is not explicitly marked as containing files
written in any one programming language. Instead, the ASP.NET infers
which compiler to invoke for the App_Code folder based on the files it
contains. If the App_Code folder contains .vb files, ASP.NET uses the
Visual Basic compiler; if it contains .cs files, ASP.NET uses the C#
compiler, and so on.
If the App_Code folder contains only files where the programming
language is ambiguous, such as a .wsdl file, ASP.NET uses the default
compiler for Web applications, as established in the compilation
element of the application Web.config file or the machine-level
Web.config file. Compilers are named build providers and a build
provider is specified for each file extension in an extension
element.
See the documentation here.
It recompiles all code in this folder in a separate assembly, then reference this assembly in your project.
You should be aware that a double reference could occur if you include these files as compilable in your project. In this latter case, the files are at the same time compiles in a separate assembly (with a temp name) which is referenced, and also compiled in the bin folder. This is the start of the horror show ...
These performance notes about the App_Code folder are slightly dated but likely still apply to the project type:
2) Keep the number of files in your /app_code directory small. If you
end up having a lot of class files within this directory, I'd
recommend you instead add a separate class library project to your VS
solution and move these classes within that instead since class
library projects compile faster than compiling classes in the
/app_code directory. This isn't usually an issue if you just have a
small number of files in /app_code, but if you have lots of
directories or dozens of files you will be able to get speed
improvements by moving these files into a separate class library
project and then reference that project from your web-site instead.
One other thing to be aware of is that whenever you switch from source
to design-view within the VS HTML designer, the designer causes the
/app_code directory to be compiled before the designer surface loads.
The reason for this is so that you can host controls defined within
/app_code in the designer. If you don't have an /app_code directory,
or only have a few files defined within it, the page designer will be
able to load much quicker (since it doesn't need to perform a big
compilation first).
-- http://weblogs.asp.net/scottgu/archive/2006/09/22/Tip_2F00_Trick_3A00_-Optimizing-ASP.NET-2.0-Web-Project-Build-Performance-with-VS-2005.aspx

Visual Studio: Automatic COM registration with dependant DLLs outside Debug/Release dirs

I've written some unmanaged C++ COM DLLs that rely on native C++ DLLs not in the system path. When I build the associated projects without copying the DLLs into the Debug/Release directories I get the infamous PRJ0050 compiler error.
Clearly I could copy required DLLs all around the solution, but I'd like to avoid this. I know I could set project properties Linker->"Register Output" to No and then run regsvr32 directly during a post build step.
My question is if there's a better way to do this. Is there a way to use the automatic "Register Output" option with a custom path controlled at the project level? What am I missing here?
Edit: Originally I'd been thinking "Register Output" did some magic like un-registering on a clean, but that isn't the case. The only thing special it seems to do is pick out the proper way to register different types of projects.
I am not sure what you are asking - but there are post build steps you can do. For example - if these are 3rd party libraries/DLLs you can have them located in a known relative path or in a directory named by an environment variable.
This is not an unusual scenario from what I can tell of your situation.
Can you add a DLL as part of the project (wherever it is located) and as the build step for that do the registration. Or you can make the build step for that a file copy and registration
Again - I am not exactly sure what you are asking and why your 2nd paragraph is not acceptable to you if it works

SimpleRepository classes and namespace missing

I am using SubSonic Active Record in a C# web application. I followed all the setup instructions and went well. i queried the database for some simple results and presto I got data. I then changed the namespace in the settings file right clicked on the ActiveRecord file and everything broke. Since then any classes and namespace generated in the ActiveRecord.cs file is not included in the project. Its like the file and the code inside ActiveRecord.cs do not exist or visual studio cannot process or recognize the files. I inspected the file and all seems well.
I am using TFS2008 if that may be the cause. I did notice earlier I also had an issue with System.Data if I pressed System. no Data namespace? This subsequently fixed itself somehow? and now I'm left trying to access the SubSonic generated classes and namespace.
Any ideas?
tks Hans
You have to make sure your project file is checked out - probably solution file too. TFS locks these things and you can't add files in unless the mechanism (your proj file) is unlocked.

how to modify SubSonic 2.1 code generation

I would like to add basic logging and make some other minor changes to the classes generated by SubSonic 2.1 (I'm not using SubSonic 3.0 t4 templates).
Is there a way to do this without modifying the SubSonic source code?
You have two choices. You can modify the default templates or create your own. I suggest making your own templates which will lives side-by-side with the original and then generate your code via the following instructions.
Note that these steps assume you ran the default SubSonic installation. In other words, Sonic.exe and the default templates can be found under c://program files/. If not, you'll find your SubSonic files/templates in an alternative installation location, of course.
Make a copy of the default templates folder as found in C:\Program Files\SubSonic\SubSonic 2.1 Final\src\SubSonic\CodeGeneration\Templates. I might recommend naming the copied folder "TemplatesWithLogging.”
Open the aspx files in Visual Studio and modify to your heart’s content. For example, I wanted an alternate C# class template so I modified CS_ClassTemplate.aspx. If you want to merely alter the default templates, you can but I suggest making a backup first.
I am going to assume you are already familiar with code generation with SubSonic. I personally like to setup a Visual Studio External Tool to allow for quick, pre-configured regeneration. Otherwise, the following can be ported over to the command line. Here’s the External Tool setup instructions:
Tools > External Tools > Add Title: TemplatesWithLogging
SubSonic Classes Command: C:\Program Files\SubSonic\SubSonic 2.1 Final\SubCommander\sonic.exe Arguments: generate /out Generated /namespace NAMESPACE /server SERVER/db DATABASE where NAMESPACE, SERVER and DATABASE are replaced accordingly.
Initial Directory: $(ProjectDir)
Check “Use Output window” and “Prompt for arguments.”
Select Apply or OK
4.Select the project which will contain the “Generated” folder and auto-generated files. Select Tool > TemplatesWithLogging.
You can find more here.
Yes you can modify the templates that version 2 uses, they're just aspx files. The templates are stored in src\SubSonic\CodeGeneration\Templates under your installation directory.
This blog post goes into more detail:
http://johnnycoder.com/blog/2008/06/09/custom-templates-with-subsonic/

Resources