0

FooBar.h

#pragma once
#include "Msg.h"

using namespace System;

namespace FooBar {
    public ref class Class1
    {
        Msg^ msg = gcnew Msg();
    };
}

Msg.h

#pragma once
#include <Windows.h>
#pragma comment (lib, "user32.lib")

ref class Msg
{
public:
    Msg();
};

Msg.cpp

#include "pch.h"
#include "Msg.h"

Msg::Msg() {
    MessageBox(0, L"FooBar", L"FooBar", MB_OK);
}

I'd successfully compile a FooBar.dll, but when running it with "rundll32 FooBar.dll" it does nothing, but it doesn't tell me that entry point should be defined at all.

I'm basically trying to do simple DLL that can be ran as test to popup a messagebox as result.

1 Answers1

0

There's a few points to consider:

  • rundll32 runs plain Win32 DLLs that follow a specific interface. You're using C++/CX to write a .Net DLL, which is a different thing. Also, you don't follow the interface.
  • What do you even want to do by "running" a DLL? Outside of .Net Core (where you use dotnet to run DLLs, not rundll32), DLLs are supposed to be libraries containing helpers for real programs, not something to be run standalone.

So depending on what you want, you can do one of these things:

  • Follow the rundll32 interface and write a plain, unmanaged function. That's possible in C++/CX. The function can even call managed code. You should not do this, though, both because rundll32 is obsolete, and because C++/CX is pretty much legacy technology too (it doesn't work with .Net Core, only with .Net Framework).
  • Write a custom program to invoke your DLL. This is what you want to do. But even in this case, you should perhaps reconsider your choice of language, if you can. (Maybe it's not your choice. But in my experience, most people who ask questions about C++/CX on SO picked it by accident and really meant to use plain C++.)
Sebastian Redl
  • 69,373
  • 8
  • 123
  • 157
  • All the information I needed. Thank you. "What do you even want to do by "running" a DLL?" I just wanted to test loading it without Visual Studio. –  Nov 06 '19 at 10:33