Hey I was trying to create an Managed Dll so i could call it from C# Im using i tried using

pragma comment (lib, "user32.lib")

I'm Continually getting linker error with the project, even though I have linked the header file and the lib to the project. Another Clue I found was in the project setting there using different calling conventions on is using __cdecl, other is defaulting to __clrcall, idk if theres a special type cast or something to fix this any ideas?I cant figure out whats causing this. Does anyone know what these problems could be related to and how to get rid of them, ive been looking at other solutions on the internet and noothing ive tried has worked

Included in the code block below are the header files and wrapper cpp
The initial header file.

#pragma once

#ifndef Included_MemoryHackCS
#define Included_MemoryHackCS

// Existing code goes here

#include <Windows.h>

namespace MemoryHacks
 {
class MemoryHackCS
{
public:
    MemoryHackCS(int pid, int data_size);
    MemoryHackCS(int pid, int data_size, unsigned int start_val);
    ~MemoryHackCS();

    static void PrintMatches();

    static bool NewScan(DWORD pid, int data_size, unsigned int start_val);
    static bool NewScan(DWORD pid, int data_size);

    static unsigned int ReadfromAddress(unsigned int addr);
    static void WriteToAddress(char s[20], unsigned int addr);

    static void SearchEquals(char s[20]);
    static void SearchDecrease();
    static void SearchIncrease();
};
 }
 #endif

The Wrapper Cpp File

// MemoryHacksWrapper.h

  #pragma once
  #pragma comment (lib, "user32.lib")

  using namespace System;

  namespace MemoryHacksWrapper {

public ref class MemoryHackCS
{
public:
    void MemoryHackCS::SearchIncrease();
    unsigned int MemoryHackCS::ReadfromAddress(unsigned int addr);

};
 }

The Wrapper Header

// This is the main DLL file.
#pragma comment (lib, "user32.lib")

#include "stdafx.h"

#include "MemoryHacksWrapper.h"

using namespace MemoryHacksWrapper;


unsigned int  MemoryHackCS::ReadfromAddress(unsigned int addr)
{
return MemoryHacks::MemoryHackCS::ReadfromAddress(addr);
}

This code returns the errors

error LNK2019: unresolved external symbol "public: static unsigned int __cdecl MemoryHacks::MemoryHackCS::ReadfromAddress(unsigned int)" (?ReadfromAddress@MemoryHackCS@MemoryHacks@@$$FSAII@Z) referenced in function "public: unsigned int __clrcall MemoryHacksWrapper::MemoryHackCS::ReadfromAddress(unsigned int)" (?ReadfromAddress@MemoryHackCS@MemoryHacksWrapper@@$$FQ$AAMII@Z) C:\Users\Grant\Documents\Visual Studio 2012\Projects\Memory\MemoryHacksWrapper\MemoryHacksWrapper.obj

Error 2 error LNK2028: unresolved token (0A000006) "public: static unsigned int __cdecl MemoryHacks::MemoryHackCS::ReadfromAddress(unsigned int)" (?ReadfromAddress@MemoryHackCS@MemoryHacks@@$$FSAII@Z) referenced in function "public: unsigned int __clrcall MemoryHacksWrapper::MemoryHackCS::ReadfromAddress(unsigned int)" (?ReadfromAddress@MemoryHackCS@MemoryHacksWrapper@@$$FQ$AAMII@Z) C:\Users\Grant\Documents\Visual Studio 2012\Projects\Memory\MemoryHacksWrapper\MemoryHacksWrapper.obj

Can anybody help me out, ive looked all over the place to resolve this I've also tried the

pragma comment (lib, "user32.lib") fix which doesnt seem to help

If you can wrapper the DLL in an MFC enabled app, you can then flip the /clr switch.
THEN you can call the methods from any dot net app.

Well Ivor Horton's beginning visual C++ 2010 (or whatever the latest version is) will teach Visual C++ (C++/CLI) and the basics of C++, that is probably what you will need for writing the wrapper properly.

But in the first place, you're going to be working on C++ source, a C++/CLI wrapper, and a C# app--pretty unhandy.

Wish I could help you more.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.