Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. how to return variable to VB.NET

how to return variable to VB.NET

Scheduled Pinned Locked Moved C / C++ / MFC
csharpdata-structuresbeta-testingjson
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    boyindie
    wrote on last edited by
    #1

    Hi I have been writing this piece of code which will search for all the possible video capture devices on the machine using the Windows DirectShow API. But no matter what I do I can't get this block of code to return the list of devices in a suitable format back to my VB.NET code. I keep getting the error pInvoke Restriction:Can't return a variant. Is there away to convert possibly the variant to a char array, and return the array back to the vb.NET GUI? The code I have is as follows :

    extern "C" __declspec(dllexport) VARIANT __cdecl getDevice()
    {
    // Create the System Device Enumerator.
    hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL,
    CLSCTX_INPROC_SERVER, IID_ICreateDevEnum,
    reinterpret_cast<void**>(&pDevEnum));

    if (SUCCEEDED(hr))
    {
    	// Create an enumerator for the video capture category.
    	hr = pDevEnum->CreateClassEnumerator(
    		CLSID\_VideoInputDeviceCategory,
    		&pEnum, 0);
    }
    
    while (pEnum->Next(1, &pMoniker, NULL) == S\_OK)
    {
    	IPropertyBag \*pPropBag;
    	hr = pMoniker->BindToStorage(0, 0, IID\_IPropertyBag, 
    		(void\*\*)(&pPropBag));
    	if (FAILED(hr))
    	{
    		pMoniker->Release();
    		continue;  // Skip this one, maybe the next one will work.
    	} 
    	// Find the description or friendly name.
    	extern VARIANT varName;
    	VariantInit(&varName);
    	hr = pPropBag->Read(L"FriendlyName", &varName, 0);
    
    	pPropBag->Release();
    	pMoniker->Release();
    }
    return varName;
    

    }

    Any feedback would be greatly appreciated Cheers Boyindie

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups