473,769 Members | 2,346 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Callback functions in c++ with managed extensions

Hi everybody,

This may seem like a Shell question, but I believe it belongs here.

I'm trying to make a wrapper class for the SHBrowseForFold er function. This
function provides for a callback to your code for certain situations. I've
done this in c# but can't seem to get it to work here.

This is the delegate:
public __delegate int BrowseCallbackP roc(HWND hWnd, UINT uMsg, LPARAM
lParam, LPARAM lpData);
This is the callback function (incomplete):
int FolderBrowserCa llBack(HWND hWnd, UINT uMsg, LPARAM lParam, LPARAM
lpData)
{
return 0;
} //FolderBrowserCa llBack

And here's the function that sets it up (somewhat incomplete):
DialogResult ShowDialog(Form * Owner)
{
DialogResult retVal = DialogResult::C ancel;
BROWSEINFO bi;
BrowseCallbackP roc* pBrowseCallback Proc = new BrowseCallbackP roc(this,
&FolderBrowser: :FolderBrowserC allBack);
ZeroMemory(&bi, sizeof(BROWSEIN FO));
bi.hwndOwner = (HWND)Owner->Handle.ToPoint er();
bi.ulFlags = (UINT)m_flags;
bi.pidlRoot = (LPITEMIDLIST)m _root;
bi.pszDisplayNa me = (LPWSTR)Marshal ::StringToCoTas kMemUni(new String('\0',
MAX_PATH)).ToPo inter();
bi.lpszTitle = (LPWSTR)Marshal ::StringToCoTas kMemUni(m_title ).ToPointer();
bi.lpfn = (BFFCALLBACK)pB rowseCallbackPr oc; // This assignment doesn't
seem to work
m_selectedPidl = SHBrowseForFold er(&bi); //
NullReferenceEx ception occurs here
if (m_selectedPidl )
{
retVal = DialogResult::O K;
} //if (m_selectedPidl )
return retVal;
} //ShowDialog
When I run the code I get a NullReferenceEx ception when calling
SHBrowseForFold er. When I step through, I find that even though
pBrowseCallback Proc appears to hold a valid address, bi.lpfn still shows
<undefinedaft er stepping through the assignment. This doesn't seem likely
to really be true because if you intentionally set this member to NULL, the
function works fine, albeit without the callback feature.

Thanks in advance for any help you can give me with this.

Paul
Feb 22 '07 #1
7 2235
Thanks in advance for any help you can give me with this.

First piece of advice: migrate to C++/CLI. Managed Extensions for C++ is no
longer maintained. There are a lot of documented bugs that MS has no
intention of fixing, and probably many more known only to Microsoft.
Feb 22 '07 #2
Paul W wrote:
I'm trying to make a wrapper class for the SHBrowseForFold er function.
There is already one: FolderBrowserDi alog, introduced in .NET 1.1.

http://msdn2.microsoft.com/en-us/lib...serdialog.aspx

That being said, is there any reason why you can't use the Microsoft
provided dialog?

Note, however, that there is (was?) a bug that caused
FolderBrowserDi alog to crash frequently with NullReferenceEx ception:

http://support.microsoft.com/kb/830920

It appears to be a .NET 1.1 problem, for which there's a hot fix.

Unfortunately I have the same problem in VS 2005 (frequent and random
crashes with FolderBrowserDi alog::ShowDialo g). I'm trying to install the
SP1 right now, and see if it makes a difference.

Tom
Feb 22 '07 #3
Hi Tom,

The FolderBrowser in .NET doesn't expose all the functionality of the
dialog. I also want it to return the PIDL for the selected folder so I can
test another control I'm writing.

"Tamas Demjen" <td*****@yahoo. comwrote in message
news:en******** ******@TK2MSFTN GP03.phx.gbl...
Paul W wrote:
I'm trying to make a wrapper class for the SHBrowseForFold er function.

There is already one: FolderBrowserDi alog, introduced in .NET 1.1.

http://msdn2.microsoft.com/en-us/lib...serdialog.aspx
>
That being said, is there any reason why you can't use the Microsoft
provided dialog?

Note, however, that there is (was?) a bug that caused
FolderBrowserDi alog to crash frequently with NullReferenceEx ception:

http://support.microsoft.com/kb/830920

It appears to be a .NET 1.1 problem, for which there's a hot fix.

Unfortunately I have the same problem in VS 2005 (frequent and random
crashes with FolderBrowserDi alog::ShowDialo g). I'm trying to install the
SP1 right now, and see if it makes a difference.

Tom

Feb 23 '07 #4
Hi Ben.

I've been out of the loop here for awhile. Am I to assume that C++/CLI is
what comes with VS 2005? Or can VS 2003 be upgraded to use this? Upgrading
to VS 2005 isn't an option for me right now.

"Ben Voigt" <rb*@nospam.nos pamwrote in message
news:u9******** ******@TK2MSFTN GP04.phx.gbl...
Thanks in advance for any help you can give me with this.

First piece of advice: migrate to C++/CLI. Managed Extensions for C++ is
no
longer maintained. There are a lot of documented bugs that MS has no
intention of fixing, and probably many more known only to Microsoft.


Feb 23 '07 #5
>I've been out of the loop here for awhile. Am I to assume that C++/CLI is
>what comes with VS 2005?
Yes.
>Or can VS 2003 be upgraded to use this?
No.

Dave
Feb 23 '07 #6
I've been out of the loop here for awhile. Am I to assume that C++/CLI is
what comes with VS 2005? Or can VS 2003 be upgraded to use this?
Upgrading
to VS 2005 isn't an option for me right now.

C++/CLI is the C++ binding to .NET.

MC++ was the first attempt to support .NET in C++. It was horrible and ugly.
C++/CLI was invented to replace MC++.

C++/CLI is here to stay, so learning it is a reasonable investment of your
time.

--

Kind regards,
Bruno van Dooren
br************* *********@hotma il.com
Remove only "_nos_pam"
Feb 23 '07 #7
Paul W wrote:
The FolderBrowser in .NET doesn't expose all the functionality of the
dialog. I also want it to return the PIDL for the selected folder so I can
test another control I'm writing.
I know that this is C# code, but it may still give you an idea, or you
can compile it to an assembly and use it from C++/CLI:

http://support.microsoft.com/kb/306285

Tom
Feb 23 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

30
19757
by: Will Pittenger | last post by:
Does C# inline functions? I do not see a inline keyword. Is there an implicit inline? Can the compiler select functions for auto-inlining? I am more used to C++ where all these things are possible. ---------- Will Pittenger E-Mail: mailto:will.pittenger@verizon.net All mail filtered by Qurb (www.qurb.com)
3
1957
by: Tommy Svensson \(InfoGrafix\) | last post by:
I've been instructed to work againt a huge unmanaged C++ API from a C# application. Now, the only way, as I've understood it, is to go the Managed Extensions for C++ way. This means I have to write a wrapper between unmanaged API and my managed app. Now on to the question: If there's an unmanaged API class called X with a defined method
0
1213
by: bob | last post by:
Hi all Currently porting an application to managed C++ Have managed to create working MDI form and child windows etc. Also added a callback from an unmanaged 'C' dll (ok that was strangely easy to do and it works). The callback simply creates a string form the callback char * data
5
3418
by: Maxwell | last post by:
Hello, Newbie question here. I have a VS.NET 2003 MC++ (not C++/cli) project where I have a managed class reference in a unmanaged class...simple enough. To keep things short I am for the most part attempting to do what is this article by Nish: http://www.voidnish.com/articles/ShowArticle.aspx?code=cbwijw I have to hook up a unmanaged callback to a managed method using IJW NOT P\Invoke. So I am employing this "Thunk" or "Bridge" class...
2
1876
by: Marcus Kwok | last post by:
I have processing code (I'll call it the "model") written in native unmanaged pure C++, and I have put a GUI on top of it written using Windows Forms (.NET 1.1). The GUI is used to set the parameters for the model, and once all parameters are set and checked to be valid, I run the model. The model takes a long time to run, so I decided to run it in a background thread, and have it notify the GUI when it is complete. The GUI will then...
7
2620
by: harishashim | last post by:
I am wrapping a digital camera API using Managed C++ VS .NET 2003). I have this function that called as bellow in the API sample. err = PR_RC_StartViewFinder( m_hCamera, //line 1 (prContext)this, //line 2 (prViewFinderCB*)&ViewFinderCallBackFun ); //line 3 prContext is actually a typedef for unsigned long. ViewFinderCallBackFun is a callback function. There is two error that I get when i tried above code unchanged:
9
3122
by: Amit Dedhia | last post by:
Hi All I have a VC++ 2005 MFC application with all classes defined as unmanaged classes. I want to write my application data in xml format. Since ADO.NET has buit in functions available for this, I want to use it. Is it possible to call Managed class functions from Unmanaged class? How to do it? I did something like this. I declared a managed class (in C++ CLI) called as MyManagedClass whose
6
7684
by: smmk25 | last post by:
Before I state the problem, I just want to let the readers know, I am knew to C++\CLI and interop so please forgive any newbie questions. I have a huge C library which I want to be able to use in a .NET application and thus am looking into writing a managed C++ wrapper for in vs2005. Furthermore, this library has many callback hooks which need to be implemented by the C++ wrapper. These callback functions are declared as "extern C...
10
7000
by: SQACPP | last post by:
Hi, I try to figure out how to use Callback procedure in a C++ form project The following code *work* perfectly on a console project #include "Windows.h" BOOL CALLBACK MyEnumWindowsProc(HWND hwnd, LPARAM lparam) {
0
10045
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9993
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9863
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8870
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7406
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3958
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.