Re: DisplayModeCollection oddity



(copied from other thread.... please try to only post your questions once)

The error is telling you that the indexer you are using is an int when it
wants a Format. In the docs, look for the 'item' property, thats what C# &
C++ use as the indexer.

So if you know the Format you want you can get the display mode. In your
case you want all of them and there is no int indexer created (though it
would seem sensible). So you can either use the Enuerator interface like you
were trying to before or use 'for each' which is much nicer.

AdapterListCollection^ adapts = Manager::Adapters ;

int adapts_count = adapts->Count ;

for( int i = 0 ; i < adapts_count ; i++ )

{

AdapterInformation^ ai = adapts[i] ;

DisplayModeCollection^ display_modes = ai->SupportedDisplayModes ;

for each (DisplayMode dm in display_modes)

{

Console::WriteLine(String::Format("Format:{0} Res:{1}x{2} Refresh:{3}Hz",
dm.Format, dm.Height, dm.Width, dm.RefreshRate));

}

Console::WriteLine(L"Press a key");

Console::ReadKey();


--
Zman
http://www.thezbuffer.com - News and information for Managed DirectX



"Peter Oliphant" <poliphant@xxxxxxxxxxxxxxxx> wrote in message
news:uqMNoPE9FHA.1028@xxxxxxxxxxxxxxxxxxxxxxx
> PS - the following line:
>
> DisplayMode^ dm = display_modes[i] ; // *odd error*
>
> is the one with the error. Although I've used 'i' incorrectly here, this
> is not the problem I'm discussing. Note that the problem occurs when
> compiling, not during execution, so the incorrect use of 'i' does not
> explain the compiler error. It generates the error even if 'i' is replaced
> with '0' (zero)...
>
> [==P==]
>
> "Peter Oliphant" <poliphant@xxxxxxxxxxxxxxxx> wrote in message
> news:u1zrYpD9FHA.4076@xxxxxxxxxxxxxxxxxxxxxxx
>> The following code generates a compiler error at the indicated line. I'm
>> using VS C++.NET 2005 Express (sorry for any wrapping effect that might
>> appear below):
>>
>> using namespace Microsoft::DirectX::Direct3D ;
>>
>> void LoadGraphics()
>> {
>> AdapterListCollection^ adapts = Manager::Adapters ;
>> int adapts_count = adapts->Count ;
>> for( int i = 0 ; i < adapts_count ; i++ )
>> {
>> AdapterInformation^ ai = adapts[i] ;
>> DisplayModeCollection^ display_modes = ai->SupportedDisplayModes ;
>> long dm_count = display_modes->Count ;
>> DisplayMode^ dm = display_modes[i] ; // *odd error*
>> }
>> }
>>
>> Error (**emphasis** mine):
>>
>> "error C2664:
>> 'Microsoft::DirectX::Direct3D::DisplayModeCollection::default::get' :
>> cannot convert **parameter 1** from 'int' to
>> 'Microsoft::DirectX::Direct3D::Format. This conversion requires an
>> explicit cast (static_cast, C-style cast or function-style cast)"
>>
>> Note that all the other lines compile without a problem (i.e., if I
>> comment out the 'error' line it compiles). In the error message, what
>> 'parameter' is it talking about? I see no parameters in this line of
>> code. All this line of code is trying to do is create a pointer to a
>> DisplayMode element in a collection. I've considered that the collection
>> is of instances and not pointers, and none of these code lines fair any
>> better:
>>
>> DisplayMode dm = display_modes[0] ; // *odd error*
>>
>> DisplayMode% dm = display_modes[0] ; // *odd error*
>>
>> This just seems weird. Any ideas what is going on here?
>>
>> Thanks in advance for responses! : )
>>
>> [==P==]
>>
>>
>>
>
>


.



Relevant Pages

  • Re: Getting Adapter Info
    ... C++ use as the indexer. ... So if you know the Format you want you can get the display mode. ... for each (DisplayMode dm in display_modes) ... > following code generates a compiler error at the indicated line. ...
    (microsoft.public.win32.programmer.directx.managed)
  • Re: DisplayModeCollection oddity
    ... Thanx, ZMan! ... > C++ use as the indexer. ... >>> The following code generates a compiler error at the indicated line. ... >>> DisplayMode element in a collection. ...
    (microsoft.public.win32.programmer.directx.managed)
  • Re: syslog-ng 3.5.3 installation on solaris10, i386
    ... configure:3612: checking for gcc ... configure:3908: checking whether the C compiler works ... | #ifdef YY_USE_CONST ... | * int a single C statement. ...
    (comp.unix.solaris)
  • Re: It Pays to Enrich Your C Skills
    ... Check if you can score a perfect 10 (without using a compiler). ... int main{ ... struct bitfield { ... out if it is a negative integer constant or a constant expression ...
    (comp.lang.c.moderated)
  • OT: Re: Perl Peeves
    ... I see the result of a test being used as an int. ... the compiler just assumed you knew what you were doing ... introduced to the language later, so void * was unheard of in most code. ... This didn't mean bool was special, declaring it just signaled to the ...
    (comp.lang.perl.misc)