{"id":19044605,"url":"https://github.com/brakmic/cpp_rest","last_synced_at":"2025-10-29T18:08:40.314Z","repository":{"id":27237353,"uuid":"30708983","full_name":"brakmic/Cpp_REST","owner":"brakmic","description":":globe_with_meridians: REST with C++ SDK (Casablanca)","archived":false,"fork":false,"pushed_at":"2015-02-12T16:40:04.000Z","size":156,"stargazers_count":18,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-18T08:39:31.679Z","etag":null,"topics":["azure","cpp","rest","restful-webservices"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/brakmic.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-02-12T15:33:34.000Z","updated_at":"2024-10-22T13:15:32.000Z","dependencies_parsed_at":"2022-09-01T03:01:18.351Z","dependency_job_id":null,"html_url":"https://github.com/brakmic/Cpp_REST","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brakmic%2FCpp_REST","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brakmic%2FCpp_REST/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brakmic%2FCpp_REST/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brakmic%2FCpp_REST/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brakmic","download_url":"https://codeload.github.com/brakmic/Cpp_REST/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250531226,"owners_count":21445946,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["azure","cpp","rest","restful-webservices"],"created_at":"2024-11-08T22:46:50.448Z","updated_at":"2025-10-29T18:08:40.209Z","avatar_url":"https://github.com/brakmic.png","language":"C++","readme":"## HTTP-Clients based on C++ REST SDK \u0026 C# ##\nThis demo consists of three small VS projects:\n\na) **C++ DLL with exported functions**\n\nb) **C++ Console App** using headers from DLL\n\nc) **C# Console App** using DllImport\n\nThe DLL Exports are as follows:\n\n\u003cimg src=\"http://p28.imgup.net/exports617e.png\" /\u003e\n\n**C++ Client App**\n\nThe C++ App uses the *Connector.h* header from DLL to create a *unique_ptr*\nof the Connector class. \n\nConnector utilizes internally the \u003ca href=\"https://casablanca.codeplex.com/\" target=\"_blank\"\u003eC++ REST SDK (Casablanca)\u003c/a\u003e to call a\npublicly available JSON Echo service.\n\n\u003cimg src=\"http://p33.imgup.net/call_echo_c916.png\"/\u003e\n\nTo make this example a little bit more realistic the method **GetJson** \nexpects a function object. This object (a function pointer) is used to\ndisplay the JSON response. There's also a possibility to send additional\nheaders.\n\nInside the **GetJson** method the server communication is handled asynchronously\nvia objects \u0026 functions from the \u003ca href=\"https://msdn.microsoft.com/de-de/library/jj987780.aspx\" target=\"_blank\"\u003epplx\u003c/a\u003e namespace.\n\n**C# Client App**\n\nThe .NET App imposes several restrictions to exported functions. \nInstead of C++ \u003ca href=\"http://en.cppreference.com/w/cpp/utility/functional/function\" target=\"_blank\"\u003efunction templates\u003c/a\u003e I had to use old-style C function\npointers. This is because .NET can only marshal Delegates to function pointers. \nThe same happened to the C++ string class. It was replaced by \nraw *wchar_t* pointers. Ugly, but playing with .NET *DllImport* is always rather\nunpleasant.\n\nThis is how the whole \u003ca href=\"https://msdn.microsoft.com/en-us/library/system.runtime.interopservices.dllimportattribute(v=vs.110).aspx\" target=\"_blank\"\u003eDllImport soup\u003c/a\u003e looks like:\n\n\u003cimg src=\"http://p82.imgup.net/csharp_clic7a7.png\" /\u003e\n\n**First**, we declare a delegate and decorate it as an \"unmanaged\" (that is, non-NET callable) function pointer. Also, we set the\ncalling convention to *StdCall*. This means that the callee (the DLL function) will be responsible to clean the stack and not the caller (the Client). More info\non argument passing and calling conventions \u003ca href=\"https://msdn.microsoft.com/en-us/library/984x0h58.aspx\" target=\"_blank\"\u003ehere\u003c/a\u003e.\n\n**Second**, we grab the DLL which hopefully exports the desired function. In this case the *Connector.dll* should be located where the executing assembly is. In other cases we'd adjust the first argument after *[DllImport]* Attribute. Also, the same calling convention is applied.\nNow, it's important to know that functions from non-NET DLLs are *statically imported externals* and very often demand special treatment of passed arguments.\nIn this case we have to marshal a pure .NET entity, the \u003ca href=\"https://msdn.microsoft.com/en-us/library/ms173171.aspx\" target=\"_blank\"\u003eDelegate\u003c/a\u003e to a raw \u003ca href=\"https://msdn.microsoft.com/en-us/library/7esfatk4%28v=vs.110%29.aspx\" target=\"_blank\"\u003efunction pointer\u003c/a\u003e To achieve this we use attribute *[MarshalAs]* and \ndecorate the *OnCompletedDelegate* as *unmanaged function pointer*.\n\n**Finally**, the C++ DLL will be able to \"call back\" our delegate as soon as the JSON Echo Server delivers a response.\n\n*Example, C++ client calling service \u0026 passing additional headers*\n\n\u003cimg src=\"http://w74.imgup.net/c_client6739.png\" /\u003e\n\n*Example, C# client calling service*\n\n\u003cimg src=\"http://p68.imgup.net/csharp_clie7d9.png\" /\u003e\n\n**IMPORTANT**\n\nThe clients need these two libraries to be located in their root folders:\n\n*Connector.dll*\n\n*cpprest120d_2_4.dll* (this is the library from C++ REST SDK and can be installed via \u003ca href=\"https://www.nuget.org/packages/cpprestsdk/\" target=\"_blank\"\u003eNuget\u003c/a\u003e)\n\n**LICENSE**\n\nMIT\n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrakmic%2Fcpp_rest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrakmic%2Fcpp_rest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrakmic%2Fcpp_rest/lists"}