Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8009247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:23:21+00:00 2026-06-04T18:23:21+00:00

I’ve stumped myself with trying to get a managed DLL to work with my

  • 0

I’ve stumped myself with trying to get a managed DLL to work with my WPF application. The idea is to call the function from within the code behind of the WPF MainWindow (so I can get the window handle) and pass that and another pointer which ends up being a pointer of type wchar_t.

I can call into the dll however the WNDProc does not launch, I think it has something to do with the instance of the application or even the handle but I can’t put my finger on it. The project builds successfully, just doesn’t run the WNDProc.

The idea of the application is to use WPF and call into c++ to start up a server instance that calls into the remote assistance API built into Windows.

Heres what I have:

#pragma once

#include "stdafx.h"
#include <winsock2.h>
#include <tchar.h>
#include "RDP.h"

#pragma warning(disable : 4996)
#pragma warning(disable : 4267)
#pragma comment(lib,"ws2_32.lib")

namespace RDPServerSession
{
RAS::SERVER* s = 0;
HWND MainWindow = 0;
HWND hL = 0;
HINSTANCE hAppInstance = 0;
wchar_t* password;

enum
{
    MESSAGE_NOTIFY = WM_USER + 2,
};

public ref class Server
{
public:
    void StartServer(System::IntPtr id, System::IntPtr handle)
    {
        password = reinterpret_cast<wchar_t*>(id.ToPointer());

        WSADATA wData;
        WSAStartup(MAKEWORD(2, 2), &wData);
        CoInitializeEx(0,COINIT_APARTMENTTHREADED);
        /*INITCOMMONCONTROLSEX icex = {0};
        icex.dwICC = ICC_LISTVIEW_CLASSES | ICC_DATE_CLASSES | ICC_WIN95_CLASSES;
        icex.dwSize = sizeof(icex);
        InitCommonControlsEx(&icex);*/
        //InitCommonControls();
        //PrepareDoMatchTable();

        hAppInstance = GetModuleHandle(NULL);

        WNDCLASSEX wClass = {0};
        wClass.cbSize = sizeof(wClass);

        wClass.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW | CS_PARENTDC;
        wClass.lpfnWndProc = (WNDPROC)Main_DP;
        wClass.hInstance = hAppInstance;
        wClass.hCursor = LoadCursor(0, IDC_ARROW);
        wClass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
        wClass.lpszClassName = _T("CLASS");
        RegisterClassEx(&wClass);

        /*MainWindow = CreateWindowEx(0,
            _T("CLASS"),
            ttitle,
            WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS |
            WS_CLIPCHILDREN, CW_USEDEFAULT, CW_USEDEFAULT,
            500, 600, 0,LoadMenu(h,_T("MENU_1")), h, 0);*/

        ShowWindow(MainWindow,SW_SHOW);

        MSG msg;

        while(GetMessage(&msg,0,0,0))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
        return;
    }



    static void StartS(HWND hh)
{
if (!s)
    {
    s = new RAS::SERVER;
    int ty = 0,po = 0,col = 16;
    bool dy = 0;

    bool Rev = false;
    if (GetKeyState(VK_CONTROL) >> 15)
        Rev = true;



    s->CreateVirtualChannel(L"test",true,CHANNEL_PRIORITY_MED);
    s->Open();
    s->SetWindowNotification(hh,MESSAGE_NOTIFY);

    vector<int> pids;
    vector<wstring> names;
    vector<int> ST;
    s->GetShareableApplications(pids,names,ST);

    RAS::S_INVITATION* inv = s->Invite(0,password,L"group",3);
    if (inv)
        {
        const wchar_t* password = inv->GetTicket().c_str();
        }

    return;
    }
else
    {
    delete s;
    s = 0;
    }
}

static LRESULT CALLBACK Main_DP(HWND hh,UINT mm,WPARAM ww,LPARAM ll)
{
switch(mm)
    {
    case WM_COMMAND:
        {
        int LW = LOWORD(ww);
        if (LW == 100)
            StartS(hh);
        return 0;
        }

    case WM_CLOSE:
        {
        if (s)
            StartS(hh);
        DestroyWindow(hh);
        return 0;
        }

    case WM_DESTROY:
        {
        PostQuitMessage(0);
        return 0;
        }
    }
return DefWindowProc(hh,mm,ww,ll);
}




    void StopServer() { delete s; }
    ~Server() { }
};

}

Any thoughts or suggestions on why it the Wndproc does not run?

Cheers.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T18:23:23+00:00Added an answer on June 4, 2026 at 6:23 pm

    The window procedure Main_DP is associated with the window class CLASS. But you don’t create a window with that class (the code is commented out) so the window procedure isn’t used.

    Update

    You want to handle messages for the existing main window, but you can’t associate a new window class with an existing window. Instead, you need to subclass the window. (As noted by Ben Voigt, you shouldn’t use the SetWindowLong technique.)

    Once you’ve subclassed the window you don’t need your own message loop. Just return to the WPF code. (And note that it may not be possible to reliably replace WPF’s message loop with your own. It may be doing more than a simple TranslateMessage/DispatchMessage.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.