Implementing Interfaces

486 views
Skip to first unread message

jmnew...@gmail.com

unread,
Apr 14, 2021, 2:49:30 PM4/14/21
to IADS
Hello, I'm having an issue with VS 2019. It's been a bit since I created a derived function and VS has updated multiple times since then. I'm not sure why, but I can't seem to find any available interfaces when creating a new function.
Implementing_interface_iads.png
Any ideas on what to do?

Thanks,
Josh Newell

Kathy Rodittis

unread,
Apr 14, 2021, 4:04:33 PM4/14/21
to ia...@googlegroups.com

Hi Josh-

It suspicious to me that the location of the IDL file is grayed out. Can you browse for the file and re-select it? Maybe it’s referencing a path that no longer exists.

-Kathy

--
You received this message because you are subscribed to the Google Groups "IADS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to iads+uns...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/iads/e2be08b1-9b1b-45f7-b9ea-7d84b5206dccn%40googlegroups.com.

image001.png

James Bretz

unread,
Apr 14, 2021, 4:07:04 PM4/14/21
to ia...@googlegroups.com
Hi Josh,

Yep, Visual Studio has definitely changed things in the recent releases. 

What language are you using? If it's C#, I think something changed where you need to compile the IadsFunction.idl into a "proper dll assembly" for it to appear in the reference section. Apparently it's unable to see the definition elsewhere in the dlls. I'm pretty sure this is a change in behavior as we just recently discovered it.

Here's a reference from the web: "I generated the TLB file with MIDL first and used TLBIMP to generate a proper DLL assembly ready to be added in the 'References...' section in my C# project.Be sure to use the tools with the correct version for your project framework. e.g, if your project framework is 3.5-based, using tlbimp from the 4.0 toolset won't work"

If you're not familiar with these tools, I just found the last dll assembly I made for another customer. I'll try sending it directly to your gmail account. If I remember correctly, you just have to unzip and extract the IadsFunction.dll file. After that, you can browse to its location in the references dialog.

As for C++, just follow the custom function tutorial as it describes how to compile and integrate the IadsFunction.idl into the project. There is a new guide called the Iads Programming Guide that's located in the  C:\Program Files (x86)\IADS\Documentation directory. If you don't have it, let me know and I can email that too. Just let me know 

Check for follow on email,
Jim




--

jmnew...@gmail.com

unread,
Apr 14, 2021, 4:17:25 PM4/14/21
to IADS
Using C++. the idl file is in the directory I expect it to be in. I can select it, but still it doesn't show any Available interfaces. 
I compared the .idl file with the previous revision I have, and there's nothing different besides the addition of the last function I created.
I followed the tutorial that I found on the website about changing the .idl Properties (MIDL->Output), but those values are what is to be expected.

Could you send me the most recent documentation?

-Josh

James Bretz

unread,
Apr 14, 2021, 4:26:04 PM4/14/21
to ia...@googlegroups.com
Josh,

I just sent you the documentation.

If I remember correctly, the interface doesn't appear in the list until you've built the project successfully once. This is also a change in behavior. It's hard to keep up with all the changes honestly.

What version of Visual Studio are you using? If I have it, I'll give it a try,
Jim

Josh Newell

unread,
Apr 14, 2021, 4:53:07 PM4/14/21
to ia...@googlegroups.com
Still not having any luck, even after building successfully. Using VS 2019 version 16.9.4.   Windows SDK 10

James Bretz

unread,
Apr 14, 2021, 5:18:55 PM4/14/21
to ia...@googlegroups.com
Josh,

Unfortunately I don't have 2019 installed. It might take a while, sorry. Let me ask around and see if someone else with 2019 can try.

Ping back if you haven't heard from me in a couple days,
Jim

James Bretz

unread,
Apr 14, 2021, 5:42:08 PM4/14/21
to ia...@googlegroups.com
Josh,

I'm on 2019 right now thanks to a coworker, VM, and RD. I should have an answer by the end of the day.

Jim

On Wed, Apr 14, 2021 at 1:53 PM Josh Newell <jmnew...@gmail.com> wrote:

James Bretz

unread,
Apr 14, 2021, 8:12:52 PM4/14/21
to ia...@googlegroups.com
Josh,

Following the tutorial in VS2019, I've noticed a couple of issues

1) While adding the class (function object) in step 5 of the tutorial, If I right click on the project name and choose "Add->Class" I don't get a dialog to choose "ATL Simple Object". To remedy this, I had to go to Solution Explorer, right click on the project and choose "Add New Item". That got me the dialog I needed to create an ATL Simple Object. We'll have to update the tutorial for 2019 for sure.

2) In step 13, while correcting the MIDL output from the Properties sheet of IadsFunction.idl, I noticed that "Generate Type Library" was set to "No". I wonder if that's that problem. Perhaps with older versions this step wasn't necessary for "implement interface"

3) In step 14, when building the project for the first time, I got a compile error. It said basically "dllmain.h: error C2065: LIBID_MyProjectNameLib': undeclared identifier". This to me indicates the output of the Midl compile (header and cpp file) isn't being included in the project. I then searched for the StdAfx.h and StdAfx.cpp files where this is normally placed and those files were nowhere to be found. After searching, I realized they renamed those files to pch.h and pch.cpp respectively. I added 

#include "IadsFunction.h" (the name of the header file you entered in step 13 in the "Header File" row.. Make sure it's not projectName.h.. unless of course they fixed their previous bugs noted in the tutorial and that works now)

into the pch.h file

Then I added
#include "IadsFunction .h"
#include " IadsFunction_i.c"

into the pch.cpp file, hit build and got a "cannot opem file 'atls.lib' (sigh)

After a quick search online, it seems the directory isn't in the path for ATL projects by default, so they suggested finding the file and adding the location under "Linker->Additional Library Directories" (Mine was at C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.27.29110\atlmfc\lib\spectre\x64 for 64 bit build). I did that, hit build again. This time it actually built... but it failed to "regsvr32" because I forgot to run DevStudio "As Administrator". Restarting Visual Studio in Admin mode fixed that issue. Clean rebuild worked 0 errors/warnings.

4) I then  went on to step number 15.. the infamous "Implement interface" step. I saw the same thing you did. It just didn't show any interfaces in the list.. very confusing..... but then I remembered that I told the MIDL compile in step 2 above to "Generate Type Library->Yes", so I changed the "Implement Interface" dialog "Implement interface from->File" and browsed to the x64 debug directory and selected the IadsFunction.tlb file and BINGO, there was the IIadsFunction interface in the list. Geez what a mess they've made of things now. I thought it was bad before, but they just keep surprising me with every new release lol.

5) After I implemented the interface, a slew of compile errors flooded in. After what I can only describe as a storm of confusing compile messages, I think I tripped on a possible answer. While implementing the interface, the wizard injected a line of code into my pch.h file "#import "C:\Jim\TestFunction\x64\Debug\IadsFunction.tlb" raw_interfaces_only, raw_native_types, no_namespace, named_guids, auto_search" with makes a bit of sense. It's trying to create the header and cpp files for the interface and include them in the project automatically. The problem is that when this line is executed, it creates an all lower case iadsfunction.tlh  file and then seemingly fails to include it because it's looking for IadsFunction.tlh (upper case first letters). I'm confused but I press on. 

6) So now I comment out the #import "C:\Jim\TestFunction\x64\Debug\IadsFunction.tlb" line in the pch.h file and hit build. It builds. Ok that's interesting.

One, we're missing something regarding the "implement interface" step. The only way I could get it to implement an interface is by pointing directly to the tlb file. I'm not sure why or how that changed. 
Second, we need to get the project to compile IadsFunction.idl to get the header files (and now the tlb file apparently to implement the interface), but once we implement the interface, the wizard injects and import statement into our pch.h file that fails to compile and then subsequently needs to be commented out.


Looks like we'll need to do a lot more work to update the C++ tutorial for Visual Studio 2019. It might take a long time to fumble through all of these issues. For now, try and go back and use the TLB method I described above... then try to survive the aftermath. You may make it out alive.

Just for reference, after that flurry of compile errors, my final pch.h file looks like:

#ifndef PCH_H
#define PCH_H

// add headers that you want to pre-compile here
#include "framework.h"

#include "IadsFunction.h"
#include "TestFunction_i.c"
//#import "C:\Jim\TestFunction\x64\Debug\IadsFunction.tlb" raw_interfaces_only, raw_native_types, no_namespace, named_guids, auto_search

#endif //PCH_H

and my pch.cpp file looks like:

/ pch.cpp: source file corresponding to the pre-compiled header

#include "pch.h"


Let me know if you make any progress or learn something new. We'll try to button this stuff up and update our tutorial asap,
Jim


On Wed, Apr 14, 2021 at 1:53 PM Josh Newell <jmnew...@gmail.com> wrote:

James Bretz

unread,
Apr 14, 2021, 8:17:54 PM4/14/21
to ia...@googlegroups.com
Josh,

Stand by for another update. I had more compile errors I didn't see originally and I see a typo in something I posted.

Jim

On Wed, Apr 14, 2021 at 1:53 PM Josh Newell <jmnew...@gmail.com> wrote:

James Bretz

unread,
Apr 14, 2021, 9:25:34 PM4/14/21
to ia...@googlegroups.com
Ok, let me try again....

7) Correction to the pch.h and pch.cpp files comment in the last email. My final pch.h looks like this:

// pch.h: This is a precompiled header file.
// Files listed below are compiled only once, improving build performance for future builds.
// This also affects IntelliSense performance, including code completion and many code browsing features.
// However, files listed here are ALL re-compiled if any one of them is updated between builds.
// Do not add files here that you will be updating frequently as this negates the performance advantage.


#ifndef PCH_H
#define PCH_H

// add headers that you want to pre-compile here
#include "framework.h"

#include "IadsFunction.h" // IadsFunction.idl MIDL header file output
#include "TestFunction.h" // The .h file from my project IDL output
//#import "C:\Jim\TestFunction\x64\Debug\IadsFunction.tlb" raw_interfaces_only, raw_native_types, no_namespace, named_guids, auto_search // The import statement that I commented out after implement

#endif //PCH_H


And my final pch.cpp looks like this:


// pch.cpp: source file corresponding to the pre-compiled header

#include "pch.h"

// When you are using pre-compiled headers, this source file is necessary for compilation to succeed.
#include "IadsFunction_i.c"


8) When I rebuilt the project after these corrections, I got an "'HRESULT IIadsFunction::Compute(VARIANT *,VARIANT *)': is abstract" error. I then looked into the functionName.h class file and I noticed the wizard implemented the function incorrectly. There seems to be more wrong than right now coming from the series of wizard.steps. Here's what it added to my class:

STDMETHOD(Compute)(VARIANT * dataIn, VARIANT * dataOut, HRESULT *Compute)
{
   return E_NOTIMPL;
}

Notice the "HRESULT* Compute" argument at the end. Where did that come from? That's not what the interface specifies in my memory. Anyway, I removed the  HRESULT* Compute at the end and it finally built.without errors.

Let me try to recap:
1) Compile IadsFunction.idl with the modifications in the properties sheet specified in the tutorial and and an additional step of "Yes" to generate the TypeLib. Build the project and hope it builds without incident (mine did). Use TypeLib (IadsFunction.tlb file) output into the Debug or Release folder of the project to implement interface (i.e. point the implement interface dialog to that tlb file)
2) After implement interface, clean up the mess the wizard generated. Comment out the #import in the pch.h file and make sure both the IadsFunction.h and YourProjectName.h file are included or you'll get compile errors. Make sure the pch.cpp file includes the IadsFunction_i.c file or you'll get link errors.
3) Correct the wizard's injection of the "Compute" function implementation in your class. Remove the last HRESULT argument.

I definitely feel like we're missing something big. It feels like we're trying to do things 'the old way', but there is some newer., much easier approach. If you or anyone stumbles on that approach, please let us know.

If you still can't get things rolling, let us know... but I have a feeling this is at least one way through the 2019 fog,
Jim














/////////////////////////
Jim

On Wed, Apr 14, 2021 at 1:53 PM Josh Newell <jmnew...@gmail.com> wrote:

Josh Newell

unread,
Apr 14, 2021, 9:45:31 PM4/14/21
to ia...@googlegroups.com
Thanks for looking at this more in depth. I will work through what you did tomorrow and see if I can find the light at the end of the tunnel. I appreciate your time and effort. Will keep you posted.

-Josh

jmnew...@gmail.com

unread,
Apr 15, 2021, 3:58:58 PM4/15/21
to IADS
I still have the stdafx.h/.cpp files as previous, and I had to comment out the IadsFunction.tlb from stdafx (caused an error for each of the functions the IIadsfunction 
After adding stdafx.h to the new function .h. I just run into these errors:
Error C1010 unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source? BFTC \IadsFunction_i.c 562
Error C1010 unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source? BFTC \IadsFunction_p.c 13766

This was then resolved (had the function.h file listed before the stdafx.h in the function.cpp file)

Now I get an abstract error 
Error C2259 'ATL::CComContainedObject<contained>': cannot instantiate abstract class C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.28.29910\atlmfc\include\atlcom.h 3449

Making progress, but not quite there yet.




James Bretz

unread,
Apr 15, 2021, 5:26:37 PM4/15/21
to ia...@googlegroups.com
cannot instantiate abstract class.... Good.. getting closer.

Check the "Compute" function signature now.. it should only have 2 variant arguments... correct it if necessary

Jim

jmnew...@gmail.com

unread,
Apr 15, 2021, 5:54:35 PM4/15/21
to IADS
The abstract issue was from a copy/paste mistake when copying from another function code, found this by diffing with another function.

Back to the two  "unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?"  errors. 
Unsure of which source file(s) it's talking about.

James Bretz

unread,
Apr 15, 2021, 6:22:15 PM4/15/21
to ia...@googlegroups.com
Oh, I thought you said you resolved that...

Anyway, according to your output

>Error C1010 unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source? >BFTC \IadsFunction_i.c 562
>Error C1010 unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source? >BFTC \IadsFunction_p.c 13766

It's claiming that the error is _iadsFunction_i.c and IadsFunction_p.c


Your StdAfx.h file should only be including .h files.. The StdAfx.cpp should include the IadsFunction_i.c file. Is that what you're doing or are you including these files directly into your project? If you are, you might have to right click on those files->Properties->C/C++->Precompiled Header->Not Using Precompiled Headers. Basically, it's saying you have options to use precompiled headers but you're not including stdafx.h.... which in this case (without modification of the _i.c file), I'm sure you're not. My best guess is that those files are in your project... and if so, you should take them out of the project and "include" them in the StdAfx.cpp. That should resolve this issue. I hope that makes sense.

If those files are not in you project, post your StdAfx.h and StdAfx.cpp file if you can,
Jim


Josh Newell

unread,
Apr 16, 2021, 1:08:45 PM4/16/21
to ia...@googlegroups.com
I got it all resolved and I think these last errors were due to initially building it in 32 bit and then changing it to 64bit afterwards, using the built 32 bit .tlb file.

I also think it had something to do with a failed attempt to rename the new function to have underscores in the name.-to use our standardized naming (One of the other things that VS2017 and on broke)

So mainly, the .tlb and commenting out that import in stdafx.h are the keys.

Thanks for the help!
-Josh


James Bretz

unread,
Apr 16, 2021, 8:25:52 PM4/16/21
to ia...@googlegroups.com
Good news! Glad you got it working ;)

Hopefully we'll get a 2019 version of the tutorial soon. This info will help in that process for sure,
Jim

Reply all
Reply to author
Forward
0 new messages