Lukket

Visual Studio C++ DLL using managed code

Hi,

I'm a programmer, but not a C++ programmer. I'm really looking for someone who can look at my example code and immediately knows what to do. I don't need someone who has to go away and look it up on Google - because I can do that myself.

I'm using Microsoft Visual Studio 2015 with /clr. C++. I'm writing a DLL.

I've written lots of unmanaged code like this, but now I'd like to incorporate some managed code, but I'm having problems combining the two. I've attached some simplified code, with an example of opening, writing and closing a file using managed code.

I call my DLL from a 3rd party app (I have no control over this 3rd party app). This app creates a single memory space for the DLL. In order to call the DLL multiple times with separate settings I create a class and use a pointer to that class for subsequent calls. The pointer is then stored in the ->Tag of the object from the 3rd party app (as an int).

The order of calling the DLL is

xCreateClass

myTest_open

myTest_write

myTest_close

xDestroyClass

The code below doesn't work because I'm redeclaring

StreamWriter^ sw

with each DLL call.

With unmanaged code I would put this file declaration in the public: scope of the myData class. But with managed code it won't allow this.

Looking on the internet it says I should declare my class with a ref statement

ref class myData

But when I do this it throws lots of errors around the use of my data pointers in the DLL calls.

So I think what I need is that my data pointers should be rewritten in managed code, but I don't know how to do this. I say I think because I'm a bit lost right now and maybe there is a different way to do this.

So hopefully you look at this code and think 'that's easy'!

If we go ahead I can send you the VS project.

Thanks

//Used to connect with 3rd party app

#import "[login to view URL]" no_namespace

#using <[login to view URL]>

using namespace System;

using namespace System::IO;

#pragma unmanaged

BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)

{

switch (ul_reason_for_call)

{

case DLL_PROCESS_ATTACH:

case DLL_THREAD_ATTACH:

case DLL_THREAD_DETACH:

case DLL_PROCESS_DETACH:

break;

}

return TRUE;

}

#pragma managed

class myData

{

public:

//variable definitions

//StreamWriter^ sw; //this declaration needs to be here, but it isn't allowed here

myData()

{

//variable declarations

}

void xx_open()

{

StreamWriter^ sw;

String^ path;

path = Environment::CurrentDirectory + "\\[login to view URL]";

if (System::IO::File::Exists(path))

System::IO::File::Delete(path);

sw = gcnew StreamWriter(path);

}

void xx_write()

{

StreamWriter^ sw; //redeclaring - doesn't work because this call is referencing a different sw from previous xx_open call

sw->WriteLine("Hello - Goodbye");

sw->Flush();

}

void xx_close()

{

StreamWriter^ sw; //redeclaring - doesn't work because this call is referencing a different sw from previous xx_open and xx_write calls

if (sw != nullptr)

{

sw->Close();

}

}

};

//DLL calls

int __stdcall xCreateClass(::IEasyLanguageObject * elObjPtr)

{

myData * myDataPtr = (myData *)elObjPtr->Tag;

if (myDataPtr == 0)

{

myDataPtr = new myData();

elObjPtr->Tag = (__int64)myDataPtr;

}

return 1;

}

int __stdcall xDestroyClass(::IEasyLanguageObject * elObjPtr)

{

myData * myDataPtr = (myData *)elObjPtr->Tag;

if (myDataPtr != 0)

{

delete myDataPtr;

elObjPtr->Tag = 0;

}

return 1;

}

void __stdcall myTest_open(::IEasyLanguageObject * elObjPtr)

{

myData * myDataPtr = (myData *)elObjPtr->Tag;

if (myDataPtr != 0)

{

myDataPtr->xx_open();

}

}

void __stdcall myTest_write(::IEasyLanguageObject * elObjPtr)

{

myData * myDataPtr = (myData *)elObjPtr->Tag;

if (myDataPtr != 0)

{

myDataPtr->xx_write();

}

}

void __stdcall myTest_close(::IEasyLanguageObject * elObjPtr)

{

myData * myDataPtr = (myData *)elObjPtr->Tag;

if (myDataPtr != 0)

{

myDataPtr->xx_close();

}

}

Evner: C++ Programmering

Se mere: using unmanaged dll in c#, enable native code debugging visual studio 2017, calling c dll from c#, calling unmanaged c++ from c#, mixing managed and unmanaged c++, c# call c++ dll, call c++ from c#, c# call native dll, visual studio vbnet view full form code, visual studio write dll, visual studio create dll, visual studio use dll wrapper, visual studio radio button checked example code, visual studio mql4 dll, visual studio 2008 dll metatrader, visual studio mt4 dll, online visual studio c++, онлайн visual studio c++, visual studio c++ online compiler, microsoft visual studio C#

Om arbejdsgiveren:
( 0 bedømmelser ) La Orotava, Spain

Projekt ID: #18305653

16 freelancere byder i gennemsnit €162 på dette job

octopus823

Hello. I have rich experiences with C/C++ programming. I can do this work with high quality. I am ready to take your project now. Lets discuss details over chat.

€155 EUR in 3 dage
(68 bedømmelser)
6.5
hbxfnzwpf

I am very proficient in java. I have 16 years java developing experience now, and have worked for more than 7 years. My work is online game developing, and mainly focus on server side, using java under Linux environmen Flere

€50 EUR på 1 dag
(87 bedømmelser)
6.6
dobreiiita

Hello, I am C++ expert and interested in this project. I have reviewed details of your project and confident to handle it perfectly. Can you please share visual studio project so I can check it. Please communicate t Flere

€125 EUR in 3 dage
(188 bedømmelser)
6.5
goalscoreplayer

How are you. Nice to meet you. I am very interested in your requirements. I have the ability to fulfill your requirements. If you hire me, I will work hard and you will get good results. Thank you

€155 EUR in 3 dage
(16 bedømmelser)
6.0
DevStar925

Hi, Dear Employer! I am really interested in your project. I have enough experience in Python, C/C++, C#, java programming. I am 100% sure I can satisfy your requirements perfectly. Clear Algorithm Will Encourage Flere

€200 EUR in 3 dage
(22 bedømmelser)
5.7
BestPartner4You

Hello, friend I am an expert in c/c++. I have already checked your description. I can help you definitely. Please send me a message so that we can discuss more details. Thanks.

€250 EUR in 3 dage
(14 bedømmelser)
5.1
itoasis1

Hi. I have review your project description. I have full experiences in Development. I am very interested in your project and also ready to start work immediately. Hoping for your soon Reply. Thank You Regard.

€50 EUR in 3 dage
(22 bedømmelser)
5.0
limillion819

Hi there. I got really excited with your project and I can say that really matches to my skills. Along as my worth experience of C++ programs, I can help and support you 100% bringing fully satisfactory result. I as Flere

€250 EUR in 5 dage
(5 bedømmelser)
4.9
dungforever

hi bro i read your description carefully and i am so interested in your project. i am confident in your project and i can finish it on time. i have many years of experience in C++/Python/Java/C#/VB.Net Object Orient Flere

€50 EUR in 3 dage
(7 bedømmelser)
3.9
C3guru

Nice to meet you, sir. I have read your job description very carefully, again and again. Having thought carefully, I conclude that I can complete your job perfectly, so I bid. In my opinion, I can wrap up your proje Flere

€250 EUR på 1 dag
(4 bedømmelser)
3.4
gardinirafael

Hi, I can show to you a method that you can solve this problem very quickly. Please chat me and let me teach you

€200 EUR in 0 dage
(2 bedømmelser)
1.8
yesikov1224

I can do any project in your demand completely by my good experiences of last ago. I have developed real projects such as data converting and data scraping by C#, C++. I have done the Mobile App projects, Web projec Flere

€155 EUR på 1 dag
(1 bedømmelse)
1.4
cemalkendo

Hey there, I think your approach is pretty complex. There is another way to create objects in dll which is way simpler. Lets discuss the details. Also ı would use standart io functions rather than streamwriter.

€250 EUR in 3 dage
(1 bedømmelse)
1.3
waseemsaleemg

Hi Dear, Our best concern is to follow your requirement and deadline and we will do our best for the success of your project. Feel free to send message to discuss your project with us. Thank you very much! Surely, we Flere

€144 EUR in 3 dage
(0 bedømmelser)
0.0
Vearfor

Cuéntame tu problema e iremos viendo. Es la primera vez que me meto en Freelancer, y no se muy bien que hacer. Entregame el codigo que tienes con la descripción del problema en castellano. Y valorare con tranquili Flere

€155 EUR in 10 dage
(0 bedømmelser)
0.0
nareshkumarch

Good to start work on C++ As Having 13+ years of experience in analysis, design, develop, manage and implementation of large C++ IT projects.

€155 EUR in 3 dage
(0 bedømmelser)
0.0