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

  • SEARCH
  • Home
  • 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 7960257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:42:13+00:00 2026-06-04T04:42:13+00:00

I want to pass a structure in C++ to a javascript function. I can

  • 0

I want to pass a structure in C++ to a javascript function. I can pass VARIANT variable to javascript but I don’t know how to convert a structure to VARIANT.

For example I can pass to function f a string that converted to VARIANT:

void f(VARIANT x);  
f(_variant_t("hello!"));

Now I want to pass a structure like this:

struct TMyStruct
{
  int x;
  int y;
};

——- Part of my code is below:

// Load Html on CHtmlView and after load is completed, get its document.
LPDISPATCH pDoc = ... // document of CHtmlView
CComQIPtr<IHTMLDocument2> m_pViewDoc;
pDoc->QueryInterface(IID_IHTMLDocument2, (void**)&m_pViewDoc);
CComPtr<IDispatch> m_pScript;
m_pViewDoc->get_Script(&m_pScript);
struct TMyStruct
{
    int x;
    int y;
    // .... other fields...
} z;
//z = .... Initialize z.
VARIANT myVariant;
// myVariant = z ????   // How to pass z to variant.
DISPID dispid = NULL;
HRESULT hr = m_pScript->GetIDsOfNames(IID_NULL, &CComBSTR(myJavaScriptFunctionName), 1, LOCALE_SYSTEM_DEFAULT, &dispid);
ATLASSERT(SUCCEEDED(hr));
if(SUCCEEDED(hr))
{
    COleDispatchDriver ocOleDispatchDriver(pScript, FALSE);
    ocOleDispatchDriver.InvokeHelperV(dispid, DISPATCH_METHOD, VT_NONE, nullptr, (BYTE*)VTS_VARIANT, myVariant);
}
  • 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-06-04T04:42:15+00:00Added an answer on June 4, 2026 at 4:42 am

    This page appears to indicate that you can’t do what you’re trying to do.

    IMPORTANT: Structs cannot be used by scripting clients!

    ref: http://vcfaq.mvps.org/com/4.htm

    It looks to me like you’ve entered the world of COM and you’re still pretty unsure how it all works. Fundamentally COM needs to know about the types you’re passing around since it enforces and manages the transition between things called COM Apartments. When crossing apartment boundaries the COM subsystem will do some magic to ensure that the COM rules are followed and nothing (too) bad can happen. It can’t do that magic unless there’s a description of the interface or type available somewhere. So, when passing structs from one C++ class to another C++ class you have some options to facilitate this, but you may not have that level of control when trying to pass the data to a scripting client.

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

Sidebar

Related Questions

I want to know how to pass structures to another function and subsequently access
I want to pass a serialized Perl data structure as a GET variable to
I have created a function for a thread, but I want to pass multiple
If I want to pass a structure defined in windows.h to one of method
I want to pass a variable to he buttonEvent method in the selector. [button
I want to pass an array of arbitrary struct pointers and a comparison function
I want to pass around some values in an array that will always be
I have a problem with common lisp. I want to pass a string to
I want to pass this structure from intent A to intent B: Hashtable> parsedData;
I'm traversing an object graph and want to pass it a block that will

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.