Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6579803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:56:37+00:00 2026-05-25T15:56:37+00:00

I have the following and I can’t shift the error surrounding the DllImport #include

  • 0

I have the following and I can’t shift the error surrounding the DllImport

#include "stdafx.h"
#include <msclr/auto_gcroot.h>

using namespace System;
using namespace System::Diagnostics;
using namespace System::Runtime::InteropServices;
using namespace System::Threading;
using namespace System::Collections::Generic;
using namespace System::Text;

namespace WinFlix
{
    class FlickWin
    {
        [DllImport("user32.dll")]
        extern "C" bool SetForegroundWindow(IntPtr hWnd);

I’ve been tranlating this class from C# where it was a static class, which is not available in C++.NET. My new C++ project is of type “CLR Console Application”.

I get

error C2059: syntax error : ‘string’

and

error C2238: unexpected token(s) preceding ‘;’

both referring to that ‘extern “C”‘ line.

I’ve searched my previous work and while I am competent with C++/CLI I’ve not had to call down into WinAPI functions like this before. Those two errors are all that are beating me :-/

TBH, this thing exhausted my patience and I deleted it, could go back and re-create it but I preferred fixing my C# instead. Help appreciated for future reference though.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T15:56:38+00:00Added an answer on May 25, 2026 at 3:56 pm

    The extern “C” is inappropriate for DllImport. That’s the source of the error.

    The problem is that you are declaring your P/invoke inside a class. As far as I can tell, in C++ they are meant to be declared as free functions outside any classes. I’ve not found much documentation for P/invoke from C++/CLI, probably because P/invoke is not needed from C++/CLI.

    You don’t need P/invoke with C++/CLI because the compiler can include standard C++ header files and link against native libraries. Just include windows.h and call the Win32 APIs with no futher effort. That’s one of the best points of C++/CLI.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following using Jquery and somehow I can resize it the right bottom
I have following CSV data: 10,11,12.34 I can parse this using CSV from the
I have the following string: cn=abcd,cn=groups,dc=domain,dc=com Can a regular expression be used here to
I have the following markup for buttons (can be changed, but I really don't
I have the following XML Document (that can be redesigned if necessary) that stores
I have the following two methods that (as you can see) are similar in
I have the following question about JPA: Can I save the order of the
I have the following code and I can't understand what does it mean: var1
I have the following HTML and you can see the extra space between the
I have the following html structure (which is generated and I can't change): <table

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.