473,386 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 SHBrowseForFolder 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 BrowseCallbackProc(HWND hWnd, UINT uMsg, LPARAM
lParam, LPARAM lpData);
This is the callback function (incomplete):
int FolderBrowserCallBack(HWND hWnd, UINT uMsg, LPARAM lParam, LPARAM
lpData)
{
return 0;
} //FolderBrowserCallBack

And here's the function that sets it up (somewhat incomplete):
DialogResult ShowDialog(Form* Owner)
{
DialogResult retVal = DialogResult::Cancel;
BROWSEINFO bi;
BrowseCallbackProc* pBrowseCallbackProc = new BrowseCallbackProc(this,
&FolderBrowser::FolderBrowserCallBack);
ZeroMemory(&bi, sizeof(BROWSEINFO));
bi.hwndOwner = (HWND)Owner->Handle.ToPointer();
bi.ulFlags = (UINT)m_flags;
bi.pidlRoot = (LPITEMIDLIST)m_root;
bi.pszDisplayName = (LPWSTR)Marshal::StringToCoTaskMemUni(new String('\0',
MAX_PATH)).ToPointer();
bi.lpszTitle = (LPWSTR)Marshal::StringToCoTaskMemUni(m_title).ToP ointer();
bi.lpfn = (BFFCALLBACK)pBrowseCallbackProc; // This assignment doesn't
seem to work
m_selectedPidl = SHBrowseForFolder(&bi); //
NullReferenceException occurs here
if (m_selectedPidl)
{
retVal = DialogResult::OK;
} //if (m_selectedPidl)
return retVal;
} //ShowDialog
When I run the code I get a NullReferenceException when calling
SHBrowseForFolder. When I step through, I find that even though
pBrowseCallbackProc appears to hold a valid address, bi.lpfn still shows
<undefinedafter 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 2217
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 SHBrowseForFolder function.
There is already one: FolderBrowserDialog, 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
FolderBrowserDialog to crash frequently with NullReferenceException:

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 FolderBrowserDialog::ShowDialog). 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**************@TK2MSFTNGP03.phx.gbl...
Paul W wrote:
I'm trying to make a wrapper class for the SHBrowseForFolder function.

There is already one: FolderBrowserDialog, 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
FolderBrowserDialog to crash frequently with NullReferenceException:

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 FolderBrowserDialog::ShowDialog). 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.nospamwrote in message
news:u9**************@TK2MSFTNGP04.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**********************@hotmail.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
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...
3
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...
0
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...
5
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...
2
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...
7
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...
9
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...
6
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...
10
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.