hi, i having some problem here. I have a DLL written in C# but I need to re-write it in C++ using visual studio 2005. I have no C++ language..o.O so could some one help guide me? help translate my code..should i use new project > 'Class Library' project or 'Win32 Console -> DLL' project? What .h file used for? and where should I put the __declspec(dllexport)? I need to function to be exported so that my 3rd party system could read it. million thanks!

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Web.Services3.Security.Tokens;
using Microsoft.Web.Services3.Security;
using Microsoft.Web.Services3;
using System.Web.Services;
using System.Web.Services.Protocols;

namespace ClassLibrarySetupProcess
{
    public class Class1
    {
        public string callSetup(string msisdn, string contractid, string customerid, string accountind, string customercode)
        {
            DateTime dt = DateTime.Now;

            string datestr = String.Format("{0:yyMMddHHmmss}", dt);

           SetupService.SetupServiceService x = new  SetupService.SetupServiceService();
            SoapContext mycon = x.RequestSoapContext;
            UsernameToken tok = new UsernameToken("MGR1", "mg01Ch", PasswordOption.SendHashed);

            mycon.Security.Tokens.Add(tok);
            x.Dispose();

            SetupService.SetupServiceRequest mpInput = new SetupService.SetupServiceRequest();
            mpInput .ReferenceID = datestr + msisdn;
            mpInput .ChannelID = "CSSMBT";
            mpInput .ChannelMedia = "TTIVR";
            mpInput .TicklerIndicator = "2";
            mpInput .MSISDN = msisdn;
            mpInput .ContractID = contractid;
            mpInput .CustomerID = customerid;
            mpInput .CustomerCode = customercode;
            mpInput .AccountIndicator = accountind;
            mpInput .TicklerCode = "MBTFTP";
            mpInput .TicklerStatus = "NOTE";
            mpInput .TicklerShortDesc = "CLOVA VIA IVR";
            mpInput .TicklerLongDesc = "Temporary Unavailable";
            mpInput .TicklerPriority = "5";



            SetupService.SetupServiceResponse wseOutput = x.SetupService(wseInput);

            return mpInput.TransactionID + "|" + mpInput.ReferenceID + "|" + mpInput.ResultStatus.StatusCode + "|" + mpInput.ResultStatus.ErrorCode + "|" + mpInput.ResultStatus.ErrorDescription;


        }
    }
}

The type of project you create will depend on where and how the DLL will be used.
If you are going to continue to use MANAGED code, there is really no need to convert the C# to C++, just use the DLL and call its functions.

If you are converting this to UNMANAGED C++, there are a lot of other things you need to consider such as how you're going to do that WebService call.

If you JUST need to create a DLL in managed C++ that does a WebService call, there are easier options.

thanks for reply, I do need to export the function in this DLL. after some research I found that __declspec(dllexport) used to export function but only in C++ that's why I need to re-write in C++.

By referring to my C# code, would you please guide me how should I add this "__declspec(dllexport)" keyword in C++?

First:
Where will the exported DLL function be used?

What I'm saying is that if it's already in a DLL, there is no need to rewrite it.

i have an application need to insert this DLL. when i insert the DLL i created in C# it prompt me no function found. so im trying __declspec(dllexport)in C++

i have an application need to insert this DLL. ...

Is the application that needs the DLL a managed (dot net) application or a native (NOT dot net) application?

Was it written in C++ or something else?

I'm assuming you have the source code to the application. Is that correct?
I'm asking so many questions because this could be a significant amount of work if it REALLY needs to be converted to a native C++ DLL.

Im sorry that i don own the source code to that application...is an application we bought from other company..i've asked that company support and they revert me try to use __declspec(dllexport) to write the DLL in C++

so im trying..

I understand now.
No, this cannot be done the way you want it to be done.

The error you will get will be:
__declspec(dllimport) cannot be applied to a member of a managed type

Your best bet would be to:
1) rename THIS method callSetup to something like callSetupM and re-compile this DLL withC#
2) create a new DLL in C++ in a class library WITH /clr turned on.
3) create an exported method called callSetup(...,...)
that calls the callSetupM method from the C# DLL

do you mean that i crate another DLL in C++ that call the C# DLL method?

then i insert the C++ DLL to the application i mentioned?

Yes. I tried an example and it worked.
Of course, I could not use your exact code because it references a web service I don't have referenced.

Here is the C# that references (and makes) a web service call:

using System.Xml;
using CSharpDll.WS_WSX;

namespace CSharpDll
{
   public class CCSharpDll
   {
      public static string GetCity(string strZip)
      {
         USZip svc = new USZip();
         XmlNode node = svc.GetInfoByZIP(strZip); 
         return (node.LastChild.SelectNodes("CITY").Item(0).InnerText);
      }
   }
}

Here is the C++ code (Win32 DLL with /clr turned on, (with MFC and MultiByte character set):

#include <afx.h>
#include "stdafx.h"
#include "CPlusPlusToCSharp.h"
using namespace System;
using namespace CSharpDll;

__declspec(dllexport) char* GetCity(char* pstrZipCode) //; use this 1 line in the header
{
	String^ strZipM = gcnew String(CString(pstrZipCode));
	static CString strRetVal;
	strRetVal = CString(CSharpDll::CCSharpDll::GetCity(strZipM));
	return strRetVal.GetBuffer(0);
}

Here is the NATIVE ONLY C++ code that references calls the hybrid DLL that calls the managed (C#) DLL:

#include "stdafx.h"
#include "c:\science\DaniWeb\CPlusPlusToCSharp\CPlusPlusToCSharp.h"

int main(void)
{
	puts(GetCity("66251"));
	return 0;
}

If YOUR native DLL has the function prototype the other software expects, then you can call a hybrid DLL that calls the one compiled in C#.

This is ONLY this complex because it's mixing native AND managed code.

commented: excellent help on an advanced topic. +10
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.