Skip to content

Instantly share code, notes, and snippets.

@daleharvey
Last active August 10, 2018 21:23
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save daleharvey/36cc005ea5aa91e9d13c5cbf0992a78f to your computer and use it in GitHub Desktop.
const nsAString& myTitle = NS_LITERAL_STRING("abc");
int len = myTitle.Length();
printf("Langth %d\n", len);
auto callback = Callback < ITypedEventHandler<DataTransferManager*, DataRequestedEventArgs* >> (
[&](IDataTransferManager*, IDataRequestedEventArgs* pArgs) -> HRESULT
{
printf("Callback called\n");
printf("Langth %d\n", len);
});
dtm->add_DataRequested(callback.Get(), &dataRequestedToken);
dtmInterop->ShowShareUIForWindow(hwnd);
// RESULTS IN
Langth 3
Callback called
Langth 1808471329
@ChrisGuzak
Copy link

ChrisGuzak commented Aug 10, 2018

repeating what Chris Swan pointed out in email, this captures len by reference and once the stack unwinds will result in a crash. fix by capturing by value [&] -> [len]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment